mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 04:21:17 +01:00
updated termsOfUse to use registration interstitial instead of being integrated into register template
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"register": "Register",
|
||||
"cancel_registration": "Cancel Registration",
|
||||
"help.email": "By default, your email will be hidden from the public.",
|
||||
"help.username_restrictions": "A unique username between %1 and %2 characters. Others can mention you with @<span id='yourUsername'>username</span>.",
|
||||
"help.minimum_password_length": "Your password's length must be at least %1 characters.",
|
||||
@@ -15,6 +16,8 @@
|
||||
"alternative_registration": "Alternative Registration",
|
||||
"terms_of_use": "Terms of Use",
|
||||
"agree_to_terms_of_use": "I agree to the Terms of Use",
|
||||
"terms_of_use_error": "You must agree to the Terms of Use",
|
||||
"registration-added-to-queue": "Your registration has been added to the approval queue. You will receive an email when it is accepted by an administrator.",
|
||||
"interstitial.intro": "We require some additional information before we can create your account."
|
||||
"interstitial.intro": "We require some additional information before we can create your account.",
|
||||
"interstitial.errors-found": "We could not complete your registration:"
|
||||
}
|
||||
@@ -88,11 +88,11 @@ function registerAndLoginUser(req, res, userData, callback) {
|
||||
}, function(err, data) {
|
||||
// If interstitials are found, save registration attempt into session and abort
|
||||
var deferRegistration = data.interstitials.length;
|
||||
deferRegistration = true;
|
||||
|
||||
if (!deferRegistration) {
|
||||
return next();
|
||||
} else {
|
||||
userData.register = true;
|
||||
req.session.registration = userData;
|
||||
return res.json({ referrer: nconf.get('relative_path') + '/register/complete' });
|
||||
}
|
||||
@@ -142,13 +142,7 @@ authenticationController.registerComplete = function(req, res, next) {
|
||||
return memo;
|
||||
}, []);
|
||||
|
||||
async.parallel(callbacks, function(err) {
|
||||
if (err) {
|
||||
req.flash('error', err.message);
|
||||
return res.redirect(nconf.get('relative_path') + '/register/complete');
|
||||
}
|
||||
|
||||
// Clear registration data in session
|
||||
var done = function() {
|
||||
delete req.session.registration;
|
||||
|
||||
if (req.session.returnTo) {
|
||||
@@ -156,10 +150,32 @@ authenticationController.registerComplete = function(req, res, next) {
|
||||
} else {
|
||||
res.redirect(nconf.get('relative_path') + '/');
|
||||
}
|
||||
}
|
||||
|
||||
async.parallel(callbacks, function(err) {
|
||||
if (err) {
|
||||
req.flash('error', err.message);
|
||||
return res.redirect(nconf.get('relative_path') + '/register/complete');
|
||||
}
|
||||
|
||||
if (req.session.registration.register === true) {
|
||||
res.locals.processLogin = true;
|
||||
registerAndLoginUser(req, res, req.session.registration, done);
|
||||
} else {
|
||||
// Clear registration data in session
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
authenticationController.registerAbort = function(req, res, next) {
|
||||
// End the session and redirect to home
|
||||
req.session.destroy(function() {
|
||||
res.redirect(nconf.get('relative_path') + '/');
|
||||
});
|
||||
};
|
||||
|
||||
authenticationController.login = function(req, res, next) {
|
||||
// Handle returnTo data
|
||||
if (req.body.hasOwnProperty('returnTo') && !req.session.returnTo) {
|
||||
|
||||
@@ -201,9 +201,11 @@ Controllers.registerInterstitial = function(req, res, next) {
|
||||
var renders = data.interstitials.map(function(interstitial) {
|
||||
return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data)
|
||||
});
|
||||
var errors = req.flash('error');
|
||||
|
||||
async.parallel(renders, function(err, sections) {
|
||||
res.render('registerComplete', {
|
||||
errors: errors,
|
||||
sections: sections
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
|
||||
router.post('/register', Auth.middleware.applyCSRF, Auth.middleware.applyBlacklist, controllers.authentication.register);
|
||||
router.post('/register/complete', Auth.middleware.applyCSRF, Auth.middleware.applyBlacklist, controllers.authentication.registerComplete);
|
||||
router.get('/register/abort', controllers.authentication.registerAbort);
|
||||
router.post('/login', Auth.middleware.applyCSRF, Auth.middleware.applyBlacklist, controllers.authentication.login);
|
||||
router.post('/logout', Auth.middleware.applyCSRF, controllers.authentication.logout);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ var async = require('async');
|
||||
var winston = require('winston');
|
||||
var controllers = require('../controllers');
|
||||
var plugins = require('../plugins');
|
||||
var user = require('../user');
|
||||
var express = require('express');
|
||||
var validator = require('validator');
|
||||
|
||||
@@ -156,6 +157,7 @@ module.exports = function(app, middleware, hotswapIds) {
|
||||
// Add plugin routes
|
||||
async.series([
|
||||
async.apply(plugins.reloadRoutes),
|
||||
async.apply(authRoutes.reloadRoutes)
|
||||
async.apply(authRoutes.reloadRoutes),
|
||||
async.apply(user.addInterstitials)
|
||||
]);
|
||||
};
|
||||
|
||||
28
src/user.js
28
src/user.js
@@ -6,6 +6,7 @@ var plugins = require('./plugins');
|
||||
var db = require('./database');
|
||||
var topics = require('./topics');
|
||||
var privileges = require('./privileges');
|
||||
var meta = require('./meta');
|
||||
var utils = require('../public/src/utils');
|
||||
|
||||
(function(User) {
|
||||
@@ -255,5 +256,32 @@ var utils = require('../public/src/utils');
|
||||
});
|
||||
};
|
||||
|
||||
User.addInterstitials = function(callback) {
|
||||
plugins.registerHook('core', {
|
||||
hook: 'filter:register.interstitial',
|
||||
method: function(data, callback) {
|
||||
if (meta.config.termsOfUse && !data.userData.acceptTos) {
|
||||
data.interstitials.push({
|
||||
template: 'partials/acceptTos',
|
||||
data: {
|
||||
termsOfUse: meta.config.termsOfUse
|
||||
},
|
||||
callback: function(userData, formData, next) {
|
||||
if (formData['agree-terms'] === 'on') {
|
||||
userData.acceptTos = true;
|
||||
}
|
||||
|
||||
next(userData.acceptTos ? null : new Error('[[register:terms_of_use_error]]'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
}
|
||||
});
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
|
||||
}(exports));
|
||||
|
||||
@@ -8,11 +8,9 @@ var plugins = require('../plugins');
|
||||
var groups = require('../groups');
|
||||
var meta = require('../meta');
|
||||
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.create = function(data, callback) {
|
||||
|
||||
data.username = data.username.trim();
|
||||
data.userslug = utils.slugify(data.username);
|
||||
if (data.email !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user