Skip to content

Commit 71fd157

Browse files
authored
Cleanup (#1876)
* Move generated data from captcha to session if available. * Completed a few WARNINGs ... tired of looking at those. ;) :) Post #944 #1867 #37 Auto-merge
1 parent 8c7fd98 commit 71fd157

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

controllers/auth.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ passport.serializeUser(function (aUser, aDone) {
4242
// Setup all the auth strategies
4343
var openIdStrategies = {};
4444
Strategy.find({}, function (aErr, aStrategies) {
45-
// WARNING: No err handling
45+
if (aErr) {
46+
// Some possible catastrophic error
47+
console.error(colors.red(aErr));
48+
49+
process.exit(1);
50+
return;
51+
}
4652

4753
// Get OpenId strategies
4854
for (var name in allStrategies) {
@@ -161,7 +167,16 @@ exports.auth = function (aReq, aRes, aNext) {
161167
if (aReq.session.cookie.sameSite !== 'lax') {
162168
aReq.session.cookie.sameSite = 'lax';
163169
aReq.session.save(function (aErr) {
164-
// WARNING: No err handling
170+
if (aErr) {
171+
// Some possible catastrophic error
172+
console.error(colors.red(aErr));
173+
174+
statusCodePage(aReq, aRes, aNext, {
175+
statusCode: 500,
176+
statusMessage: 'Save Session failed.'
177+
});
178+
return;
179+
}
165180

166181
authenticate(aReq, aRes, aNext);
167182
});
@@ -171,6 +186,7 @@ exports.auth = function (aReq, aRes, aNext) {
171186
}
172187

173188
function sessionauth() {
189+
var captchaToken = aReq.body['g-captcha-response'] ?? aReq.body['h-captcha-response'];
174190
// Yet another passport hack.
175191
// Initialize the passport session data only when we need it. i.e. late binding
176192
if (!aReq.session[passportKey] && aReq._passport.session) {
@@ -180,6 +196,16 @@ exports.auth = function (aReq, aRes, aNext) {
180196

181197
// Save redirect url from the form submission on the session
182198
aReq.session.redirectTo = aReq.body.redirectTo || getRedirect(aReq);
199+
200+
// Save the token from the captcha on the session and remove from body
201+
if (captchaToken) {
202+
aReq.session.captchaToken = captchaToken;
203+
aReq.session.captchaSuccess = aReq.hcaptcha;
204+
205+
delete aReq.body['g-captcha-response'];
206+
delete aReq.body['h-captcha-response'];
207+
delete aReq.hcaptcha;
208+
}
183209
}
184210

185211
function anteauth() {
@@ -411,7 +437,16 @@ exports.callback = function (aReq, aRes, aNext) {
411437

412438
if (!aReq.session.passport.oujsOptions.authAttach) {
413439
expandSession(aReq, aUser, function (aErr) {
414-
// WARNING: No err handling
440+
if (aErr) {
441+
// Some possible catastrophic error
442+
console.error(colors.red(aErr));
443+
444+
statusCodePage(aReq, aRes, aNext, {
445+
statusCode: 500,
446+
statusMessage: 'Expand Session failed.'
447+
});
448+
return;
449+
}
415450

416451
aRes.redirect(doneUri);
417452
});

0 commit comments

Comments
 (0)