Skip to content

Commit e04e822

Browse files
authored
Modified our fork a bit (#1873)
* Whoops... verify happens in parent dep of our fork... so no need to do this in our code. Ahh more time spent learning the hard way. LOL * Modified fork to accept `SITEKEY` because we expect that to go that way. * Consolidated the `sessionauth` since that's going to be a future thing with code migration. * We have the ability to send the IP to them but need to query the establishing owner first. Post #944 #1867 Auto-merge
1 parent 2352b94 commit e04e822

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

controllers/auth.js

+18-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ var isDbg = require('../libs/debug').isDbg;
88
//
99

1010
//--- Dependency inclusions
11-
var request = require('request');
1211
var passport = require('passport');
1312
var url = require('url');
1413
var colors = require('ansi-colors');
@@ -162,6 +161,18 @@ exports.auth = function (aReq, aRes, aNext) {
162161
}
163162
}
164163

164+
function sessionauth() {
165+
// Yet another passport hack.
166+
// Initialize the passport session data only when we need it. i.e. late binding
167+
if (!aReq.session[passportKey] && aReq._passport.session) {
168+
aReq.session[passportKey] = {};
169+
aReq._passport.session = aReq.session[passportKey];
170+
}
171+
172+
// Save redirect url from the form submission on the session
173+
aReq.session.redirectTo = aReq.body.redirectTo || getRedirect(aReq);
174+
}
175+
165176
function anteauth() {
166177
// Store the useragent always so we still have it when they
167178
// get back from authentication and/or attaching
@@ -222,41 +233,19 @@ exports.auth = function (aReq, aRes, aNext) {
222233
return;
223234
}
224235

236+
sessionauth();
225237

226-
// TODO: Send out token and sitekey back to https://hcaptcha.com/siteverify
227-
// ... routine with req hcaptcha?
228-
// If successful then do below and call anteauth otherwise redirect
229-
230-
// Yet another passport hack.
231-
// Initialize the passport session data only when we need it. i.e. late binding
232-
if (!aReq.session[passportKey] && aReq._passport.session) {
233-
aReq.session[passportKey] = {};
234-
aReq._passport.session = aReq.session[passportKey];
235-
}
236-
237-
// Save redirect url from the form submission on the session
238-
aReq.session.redirectTo = aReq.body.redirectTo || getRedirect(aReq);
239-
240-
// Store the username always so we still have it when they
241-
// get back from authentication
242-
aReq.session.username = username;
243-
244-
anteauth();
238+
// Store the username always so we still have it when they
239+
// get back from authentication
240+
aReq.session.username = username;
245241

242+
anteauth();
246243

247244
} else {
248245
// Already validated username
249246
username = aReq.session.username || (authedUser ? authedUser.name : null);
250247

251-
// Yet another passport hack.
252-
// Initialize the passport session data only when we need it. i.e. late binding
253-
if (!aReq.session[passportKey] && aReq._passport.session) {
254-
aReq.session[passportKey] = {};
255-
aReq._passport.session = aReq.session[passportKey];
256-
}
257-
258-
// Save redirect url from the form submission on the session
259-
aReq.session.redirectTo = aReq.body.redirectTo || getRedirect(aReq);
248+
sessionauth();
260249

261250
// Allow a logged in user to add a new strategy
262251
if (strategy) {

routes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var MongoStore = require('rate-limit-mongo');
1010
var exec = require('child_process').exec;
1111
var hcaptcha = require('express-hcaptcha');
1212
var SECRET = process.env.HCAPTCHA_SECRET_KEY;
13+
var SITEKEY = process.env.HCAPTCHA_SITE_KEY;
1314

1415
//
1516
var main = require('./controllers/index');
@@ -123,7 +124,7 @@ module.exports = function (aApp) {
123124

124125
//--- Routes
125126
// Authentication routes
126-
aApp.route('/auth/').post(authentication.preauth, hcaptcha.middleware.validate(SECRET),
127+
aApp.route('/auth/').post(authentication.preauth, hcaptcha.middleware.validate(SECRET, SITEKEY),
127128
function (aErr, aReq, aRes, aNext) {
128129
if (aErr) {
129130
aRes.redirect(302, '/login?authfail');

0 commit comments

Comments
 (0)