v1.18.x
Julian Lam 7 years ago
parent 9132743870
commit 99f1a5380e

@ -191,8 +191,18 @@ authenticationController.registerComplete = function (req, res, next) {
res.locals.processLogin = true;
registerAndLoginUser(req, res, req.session.registration, done);
} else {
// Clear registration data in session
done();
// Update user hash, clear registration data in session
const payload = req.session.registration;
const uid = payload.uid;
delete payload.uid;
Object.keys(payload).forEach((prop) => {
if (typeof payload[prop] === 'boolean') {
payload[prop] = payload[prop] ? 1 : 0;
}
});
user.setUserFields(uid, payload, done);
}
});
});

@ -197,7 +197,7 @@ Controllers.registerInterstitial = function (req, res, next) {
if (!data.interstitials.length) {
// No interstitials, redirect to home
delete req.session.registration;
return res.redirect('/');
return res.redirect(nconf.get('relative_path') + '/');
}
var renders = data.interstitials.map(function (interstitial) {
return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {});

@ -215,6 +215,9 @@ module.exports = function (middleware) {
return next();
}
if (!req.path.endsWith('/register/complete')) {
// Append user data if present
req.session.registration.uid = req.uid;
controllers.helpers.redirect(res, '/register/complete');
} else {
return next();

@ -66,7 +66,11 @@ Auth.reloadRoutes = function (callback) {
}));
}
router.get(strategy.callbackURL, passport.authenticate(strategy.name, {
router.get(strategy.callbackURL, function (req, res, next) {
// Trigger registration interstitial checks
req.session.registration = req.session.registration || {};
next();
}, passport.authenticate(strategy.name, {
successReturnToOrRedirect: nconf.get('relative_path') + (strategy.successUrl !== undefined ? strategy.successUrl : '/'),
failureRedirect: nconf.get('relative_path') + (strategy.failureUrl !== undefined ? strategy.failureUrl : '/login'),
}));

@ -353,7 +353,7 @@ User.addInterstitials = function (callback) {
method: [
// GDPR information collection/processing consent + email consent
function (data, callback) {
if (!data.userData.gdpr_consent) {
const add = function () {
data.interstitials.push({
template: 'partials/gdpr_consent',
data: {
@ -368,14 +368,32 @@ User.addInterstitials = function (callback) {
next(userData.gdpr_consent ? null : new Error('[[register:gdpr_consent_denied]]'));
},
});
}
};
if (!data.userData.gdpr_consent) {
if (data.userData.uid) {
db.getObjectField('user:' + data.userData.uid, 'gdpr_consent', function (err, consented) {
if (err) {
return callback(err);
} else if (!parseInt(consented, 10)) {
add();
}
setImmediate(callback, null, data);
callback(null, data);
});
} else {
add();
setImmediate(callback, null, data);
}
} else {
// GDPR consent signed
setImmediate(callback, null, data);
}
},
// Forum Terms of Use
function (data, callback) {
if (meta.config.termsOfUse && !data.userData.acceptTos) {
const add = function () {
data.interstitials.push({
template: 'partials/acceptTos',
data: {
@ -389,9 +407,27 @@ User.addInterstitials = function (callback) {
next(userData.acceptTos ? null : new Error('[[register:terms_of_use_error]]'));
},
});
}
};
if (meta.config.termsOfUse && !data.userData.acceptTos) {
if (data.userData.uid) {
db.getObjectField('user:' + data.userData.uid, 'acceptTos', function (err, accepted) {
if (err) {
return callback(err);
} else if (!parseInt(accepted, 10)) {
add();
}
setImmediate(callback, null, data);
callback(null, data);
});
} else {
add();
setImmediate(callback, null, data);
}
} else {
// TOS accepted
setImmediate(callback, null, data);
}
},
],
});

@ -47,6 +47,7 @@ module.exports = function (User) {
banned: 0,
status: 'online',
gdpr_consent: data.gdpr_consent === true ? 1 : 0,
acceptTos: data.acceptTos === true ? 1 : 0,
};
User.uniqueUsername(userData, next);

Loading…
Cancel
Save