forked from klaudgrave/discourse-google-recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.html
283 lines (260 loc) · 10.7 KB
/
component.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!--Add this in Customize - Themes - Components - <head> -->
<!-- don't forget to change 'sitekey' to actual sitekey -->
<!DOCTYPE html>
<script src="https://www.google.com/recaptcha/api.js" async defer ></script>
<script type="text/x-handlebars" data-template-name="modal/create-account">
{{#create-account email=accountEmail disabled=submitDisabled action=(action "createAccount")}}
{{#unless complete}}
{{plugin-outlet name="create-account-before-modal-body" tagName="span" connectorTagName="div"}}
{{#d-modal-body class=modalBodyClasses preventModalAlertHiding=true}}
<div class="create-account-form">
<div class="login-welcome-header" id="create-account-title">
<h1 class="login-title">{{i18n "create_account.header_title"}}</h1> <img src={{wavingHandURL}} alt="" class="waving-hand">
<p class="login-subheader">{{i18n "create_account.subheader_title"}}</p>
</div>
{{#if showCreateForm}}
<div class="login-form">
<form>
{{#if associateHtml}}
<div class="input-group create-account-associate-link">
<span>{{html-safe associateHtml}}</span>
</div>
{{/if}}
<div class="input-group create-account-email">
{{input
type="email"
disabled=emailDisabled
value=accountEmail
id="new-account-email"
name="email"
class=(value-entered accountEmail)
autofocus="autofocus"
focusOut=(action "checkEmailAvailability")
aria-describedby="account-email-validation"
aria-invalid=emailValidation.failed
}}
<label class="alt-placeholder" for="new-account-email">
{{i18n "user.email.title"}}
{{~#if userFields~}}
<span class="required">*</span>
{{/if}}
</label>
{{input-tip validation=emailValidation id="account-email-validation"}}
<span class="more-info">{{i18n "user.email.instructions"}}</span>
</div>
<div class="input-group">
{{input
value=accountUsername
disabled=usernameDisabled
class=(value-entered accountUsername)
id="new-account-username"
name="username"
maxlength=maxUsernameLength
aria-describedby="username-validation"
aria-invalid=usernameValidation.failed
autocomplete="off"
}}
<label class="alt-placeholder" for="new-account-username">
{{i18n "user.username.title"}}
{{~#if userFields~}}
<span class="required">*</span>
{{/if}}
</label>
{{input-tip validation=usernameValidation id="username-validation"}}
<span class="more-info">{{i18n "user.username.instructions"}}</span>
</div>
<div class="input-group">
{{#if fullnameRequired}}
{{text-field
disabled=nameDisabled
value=accountName
id="new-account-name"
class=(value-entered accountName)
aria-describedby="fullname-validation"
aria-invalid=nameValidation.failed
}}
<label class="alt-placeholder" for="new-account-name">
{{i18n "user.name.title"}}
{{#if siteSettings.full_name_required}}
{{~#if userFields~}}
<span class="required">*</span>
{{/if}}
{{/if}}
</label>
{{input-tip validation=nameValidation id="fullname-validation"}}
<span class="more-info">{{nameInstructions}}</span>
{{/if}}
</div>
{{plugin-outlet
name="create-account-before-password"
args=(hash
accountName=accountName
accountUsername=accountUsername
accountPassword=accountPassword
userFields=userFields
authOptions=authOptions
)
}}
<div class="input-group">
{{#if passwordRequired}}
{{password-field
value=accountPassword
class=(value-entered accountPassword)
type="password"
id="new-account-password"
autocomplete="current-password"
capsLockOn=capsLockOn
aria-describedby="password-validation"
aria-invalid=passwordValidation.failed
}}
<label class="alt-placeholder" for="new-account-password">
{{i18n "user.password.title"}}
{{~#if userFields~}}
<span class="required">*</span>
{{/if}}
</label>
{{input-tip validation=passwordValidation id="password-validation"}}
<span class="more-info">{{passwordInstructions}}</span>
<div class="caps-lock-warning {{unless capsLockOn " hidden"}}">
{{d-icon "exclamation-triangle"}} {{i18n "login.caps_lock_warning"}}
</div>
{{/if}}
<div class="password-confirmation">
<label for="new-account-password-confirmation">{{i18n "user.password_confirmation.title"}}</label>
{{honeypot-input id="new-account-confirmation" autocomplete="new-password" value=accountHoneypot}}
{{input value=accountChallenge id="new-account-challenge"}}
</div>
</div>
{{#if requireInviteCode }}
<div class="input-group">
{{input value=inviteCode class=(value-entered inviteCode) id="inviteCode"}}
<label class="alt-placeholder" for="invite-code">{{i18n "user.invite_code.title"}}</label>
<span class="more-info">{{i18n "user.invite_code.instructions"}}</span>
</div>
{{/if}}
{{plugin-outlet
name="create-account-after-password"
args=(hash
accountName=accountName
accountUsername=accountUsername
accountPassword=accountPassword
userFields=userFields
)
}}
<tr>
<td>
<div class="g-recaptcha" id="recaptcha" data-sitekey="6LdQTWYgAAAAADzU6B3w5fBNAultAxGNETWR4JA9"></div>
<input type="hidden" value="" id="gr-ver" />
</td>
</tr>
{{#if userFields}}
<div class="user-fields">
{{#each userFields as |f|}}
<div class="input-group">
{{!-- adding the value-entered class here to
be able to detect if the user field has a value
entered --}}
{{user-field field=f.field value=f.value
class=(value-entered f.value)}}
</div>
{{/each}}
</div>
{{/if}}
</form>
</div>
<div class="modal-footer">
{{d-button
class="btn-large btn-primary"
action=(action "createAccount")
disabled=submitDisabled
label="create_account.title"
isLoading=formSubmitted
}}
{{#unless hasAuthOptions}}
{{d-button class="btn-large" id="login-link" action=(route-action "showLogin") disabled=formSubmitted label="log_in"}}
{{/unless}}
<div class="disclaimer">
{{html-safe disclaimerHtml}}
</div>
</div>
{{plugin-outlet name="create-account-after-modal-footer" connectorTagName="div"}}
{{/if}}
{{#unless hasAuthOptions}}
<div class="create-account-login-buttons">
{{login-buttons externalLogin=(action "externalLogin")}}
</div>
{{/unless}}
{{#if skipConfirmation}}
{{loading-spinner size="large"}}
{{/if}}
</div>
{{/d-modal-body}}
{{/unless}}
{{/create-account}}
</script>
<script type="text/javascript">
$(document).ready(function() {
$('.sign-up-button').click(function() {
_captchaTries = 0;
recaptchaOnLoad();
});
});
function signUpClick() {
var grecaptchaResponse = grecaptcha.getResponse();
var btn = $('#btn-sign-up');
btn.prop('disabled', true);
$.ajax({
url: '/grverify',
type: 'POST',
dataType: 'json',
data: {
recaptcha_response: grecaptchaResponse
},
success: function (res) {
console.log(res);
var enabled = btn.prop('disabled');
var verified = res.verify;
if (enabled && verified) {
btn.prop('disabled', false);
$('#gr-ver').val('yes');
}
},
error: function (jqXHR, exception) {
console.log('failure'); console.log(jqXHR); console.log(exception);
btn.prop('disabled', true);
}
});
//});
}
function recaptchaOnLoad() {
_captchaTries++;
if(_captchaTries > 9)
return;
if ($('.ember-text-field').length > 1) {
$('#no-enter-form').on('keyup keypress', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
$('.ember-text-field').change(function(){
$('#btn-sign-up').prop('disabled', true);
if ( $('.tip.good').length == 4 && $('#gr-ver').val == 'yes') {
$('#btn-sign-up').prop('disabled', false);
}
});
}
if ( $('.g-recaptcha').length > 0 ) {
grecaptcha.render("recaptcha", {
sitekey: "sitekey",
callback: function() {
console.log('rec callback');
signUpClick();
}
});
return;
}
window.setTimeout(recaptchaOnLoad, 1000);
}
</script>