@@ -84,7 +84,6 @@ exports.preauth = function (aReq, aRes, aNext) {
84
84
var authedUser = aReq . session . user ;
85
85
86
86
var username = aReq . body . username ;
87
- var SECRET = process . env . HCAPTCHA_SECRET_KEY ;
88
87
var SITEKEY = process . env . HCAPTCHA_SITE_KEY ;
89
88
90
89
if ( ! authedUser ) {
@@ -115,19 +114,28 @@ exports.preauth = function (aReq, aRes, aNext) {
115
114
return ;
116
115
}
117
116
118
- if ( aUser || ! SECRET ) {
117
+ if ( aUser ) {
119
118
// Ensure that casing is identical so we still have it, correctly, when they
120
119
// get back from authentication
121
120
aReq . body . username = aUser . name ;
122
121
123
- // Skip captcha for known individual and not implemented
122
+ if ( aUser ) {
123
+ aReq . knownUser = true ;
124
+ }
125
+
126
+ // Skip captcha for known individual
124
127
exports . auth ( aReq , aRes , aNext ) ;
125
128
} else {
126
129
// Match cleansed name and this is the casing they have chosen
127
130
aReq . body . username = username ;
128
131
129
132
// Validate captcha for unknown individual
130
- aNext ( ) ;
133
+ if ( ! SITEKEY ) {
134
+ // Skip captcha for not implemented
135
+ exports . auth ( aReq , aRes , aNext ) ;
136
+ } else {
137
+ aNext ( ) ;
138
+ }
131
139
}
132
140
} ) ;
133
141
} else {
@@ -197,6 +205,10 @@ exports.auth = function (aReq, aRes, aNext) {
197
205
// Save redirect url from the form submission on the session
198
206
aReq . session . redirectTo = aReq . body . redirectTo || getRedirect ( aReq ) ;
199
207
208
+ // Save the known user on the session and remove
209
+ aReq . session . knownUser = aReq . knownUser ;
210
+ delete aReq . knownUser ;
211
+
200
212
// Save the token from the captcha on the session and remove from body
201
213
if ( captchaToken ) {
202
214
aReq . session . captchaToken = captchaToken ;
@@ -301,8 +313,17 @@ exports.callback = function (aReq, aRes, aNext) {
301
313
var strategy = aReq . params . strategy ;
302
314
var username = aReq . session . username ;
303
315
var newstrategy = aReq . session . newstrategy ;
316
+ var knownUser = aReq . session . knownUser ;
317
+ var captchaToken = aReq . session . captchaToken ;
304
318
var strategyInstance = null ;
305
319
var doneUri = aReq . session . user ? '/user/preferences' : '/' ;
320
+ var SITEKEY = process . env . HCAPTCHA_SITE_KEY ;
321
+
322
+
323
+ if ( SITEKEY && ! knownUser && ! captchaToken ) {
324
+ aRes . redirect ( '/login?fail' ) ;
325
+ return ;
326
+ }
306
327
307
328
// The callback was called improperly or sesssion expired
308
329
if ( ! strategy || ! username ) {
0 commit comments