mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-31 19:15:58 +01:00
Squashed commit of the following:
commit 9c86d9b2904e14927cd7e9679b92aec0951d1063 Merge: ebfa63a5a7f811Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 20 08:41:39 2017 -0400 Merge branch 'noscript-login' of https://github.com/An-dz/NodeBB into noscript commit5a7f81185eAuthor: André Zanghelini <an_dz@simutrans-forum> Date: Mon Jul 17 23:07:14 2017 -0300 Rename clashing variable 'next' commit ebfa63a984073a58c17aa408c363cdb03ef89985 Merge: c1801cdf159d0dAuthor: Julian Lam <julian@nodebb.org> Date: Mon Jul 17 16:30:40 2017 -0400 Merge branch 'noscript-logout' of https://github.com/An-dz/NodeBB into noscript commit c1801cda14e6363491e30b659902e2ae71f7e1f7 Merge: 7a5f9f39fd542dAuthor: Julian Lam <julian@nodebb.org> Date: Mon Jul 17 16:30:31 2017 -0400 Merge branch 'noscript-register' of https://github.com/An-dz/NodeBB into noscript commit 7a5f9f35abc834bb72ddddc9ca07d34f2fde8353 Merge:44851f9d37b95cAuthor: Julian Lam <julian@nodebb.org> Date: Mon Jul 17 16:30:10 2017 -0400 Merge branch 'noscript-compose' of https://github.com/An-dz/NodeBB into noscript commitf159d0d9efAuthor: André Zanghelini <an_dz@simutrans-forum> Date: Thu Jul 6 12:16:38 2017 -0300 Prevent form submit Required for theme change commitd37b95cb71Author: André Zanghelini <an_dz@simutrans-forum> Date: Thu Jul 6 01:49:52 2017 -0300 Prevent link action with scripts Required for the theme change that changes the buttons to `a` tags. commit9fd542d897Author: André Zanghelini <an_dz@simutrans-forum> Date: Wed Jul 5 19:57:56 2017 -0300 Fix tests commitcdad5bf8c2Author: André Zanghelini <an_dz@simutrans-forum> Date: Wed Jul 5 19:09:17 2017 -0300 Update error handling commit4ff11cd136Author: André Zanghelini <an_dz@simutrans-forum> Date: Wed Jul 5 17:29:08 2017 -0300 Remove async waterfall commitdf01d44e82Author: André Zanghelini <an_dz@simutrans-forum> Date: Wed Jul 5 16:59:43 2017 -0300 Set noscript compose as noscript at start commit4bcc380da7Author: André Zanghelini <an_dz@simutrans-forum> Date: Wed Jul 5 16:59:12 2017 -0300 Remove last useless next commitb5eac6fea1Author: André Zanghelini <an_dz@simutrans-forum> Date: Sun Jul 2 18:35:08 2017 -0300 Last function requires no next commit20a5cce6e6Author: André Zanghelini <an_dz@simutrans-forum> Date: Sun Jul 2 18:06:58 2017 -0300 Remove more useless next calls commit85ee22a79bAuthor: André Zanghelini <an_dz@simutrans-forum> Date: Sun Jul 2 17:46:07 2017 -0300 Remove useless next calls commit7d984c47adAuthor: André Zanghelini <an_dz@simutrans-forum> Date: Sun Jul 2 15:45:31 2017 -0300 Support old themes commit4a09dfbd08Author: André Zanghelini <an_dz@simutrans-forum> Date: Sun Jul 2 15:37:23 2017 -0300 Moved all error handling into helpers function commit391aa6e67eAuthor: André Zanghelini <an_dz@simutrans-forum> Date: Thu Jun 8 15:37:37 2017 -0300 ESLint - Fix mixed conditionals commit80ccc6fd58Author: André Zanghelini <an_dz@simutrans-forum> Date: Sat Jun 3 18:08:15 2017 -0300 Compose without scripts commit2aca811256Author: André Zanghelini <an_dz@simutrans-forum> Date: Sat Jun 3 18:00:44 2017 -0300 Register without scripts commit097bb51577Author: André Zanghelini <an_dz@simutrans-forum> Date: Sat Jun 3 16:42:15 2017 -0300 Logout without scripts commitd497e08109Author: André Zanghelini <an_dz@simutrans-forum> Date: Sat Jun 3 16:27:10 2017 -0300 Login without script
This commit is contained in:
@@ -14,6 +14,7 @@ var plugins = require('../plugins');
|
||||
var utils = require('../utils');
|
||||
var Password = require('../password');
|
||||
var translator = require('../translator');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
var sockets = require('../socket.io');
|
||||
|
||||
@@ -49,6 +50,10 @@ authenticationController.register = function (req, res) {
|
||||
return next(new Error('[[error:username-too-long]]'));
|
||||
}
|
||||
|
||||
if (userData.password !== userData['password-confirm']) {
|
||||
return next(new Error('[[user:change_password_error_match]]'));
|
||||
}
|
||||
|
||||
user.isPasswordValid(userData.password, next);
|
||||
},
|
||||
function (next) {
|
||||
@@ -67,7 +72,7 @@ authenticationController.register = function (req, res) {
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return res.status(400).send(err.message);
|
||||
return helpers.noScriptErrors(req, res, err.message, 400);
|
||||
}
|
||||
|
||||
if (data.uid && req.body.userLang) {
|
||||
@@ -96,6 +101,10 @@ function registerAndLoginUser(req, res, userData, callback) {
|
||||
}
|
||||
userData.register = true;
|
||||
req.session.registration = userData;
|
||||
|
||||
if (req.body.noscript === 'true') {
|
||||
return res.redirect(nconf.get('relative_path') + '/register/complete');
|
||||
}
|
||||
return res.json({ referrer: nconf.get('relative_path') + '/register/complete' });
|
||||
},
|
||||
function (next) {
|
||||
@@ -200,22 +209,22 @@ authenticationController.login = function (req, res, next) {
|
||||
} else if (loginWith.indexOf('username') !== -1 && !validator.isEmail(req.body.username)) {
|
||||
continueLogin(req, res, next);
|
||||
} else {
|
||||
res.status(500).send('[[error:wrong-login-type-' + loginWith + ']]');
|
||||
var err = '[[error:wrong-login-type-' + loginWith + ']]';
|
||||
helpers.noScriptErrors(req, res, err, 500);
|
||||
}
|
||||
};
|
||||
|
||||
function continueLogin(req, res, next) {
|
||||
passport.authenticate('local', function (err, userData, info) {
|
||||
if (err) {
|
||||
return res.status(403).send(err.message);
|
||||
return helpers.noScriptErrors(req, res, err.message, 403);
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
if (typeof info === 'object') {
|
||||
info = '[[error:invalid-username-or-password]]';
|
||||
}
|
||||
|
||||
return res.status(403).send(info);
|
||||
return helpers.noScriptErrors(req, res, info, 403);
|
||||
}
|
||||
|
||||
var passwordExpiry = userData.passwordExpiry !== undefined ? parseInt(userData.passwordExpiry, 10) : null;
|
||||
@@ -235,7 +244,7 @@ function continueLogin(req, res, next) {
|
||||
req.session.passwordExpired = true;
|
||||
user.reset.generate(userData.uid, function (err, code) {
|
||||
if (err) {
|
||||
return res.status(403).send(err.message);
|
||||
return helpers.noScriptErrors(req, res, err.message, 403);
|
||||
}
|
||||
|
||||
res.status(200).send(nconf.get('relative_path') + '/reset/' + code);
|
||||
@@ -243,16 +252,21 @@ function continueLogin(req, res, next) {
|
||||
} else {
|
||||
authenticationController.doLogin(req, userData.uid, function (err) {
|
||||
if (err) {
|
||||
return res.status(403).send(err.message);
|
||||
return helpers.noScriptErrors(req, res, err.message, 403);
|
||||
}
|
||||
|
||||
var destination;
|
||||
if (!req.session.returnTo) {
|
||||
res.status(200).send(nconf.get('relative_path') + '/');
|
||||
destination = nconf.get('relative_path') + '/';
|
||||
} else {
|
||||
var next = req.session.returnTo;
|
||||
destination = req.session.returnTo;
|
||||
delete req.session.returnTo;
|
||||
}
|
||||
|
||||
res.status(200).send(next);
|
||||
if (req.body.noscript === 'true') {
|
||||
res.redirect(destination + '?loggedin');
|
||||
} else {
|
||||
res.status(200).send(destination);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -404,7 +418,11 @@ authenticationController.logout = function (req, res, next) {
|
||||
function () {
|
||||
// Force session check for all connected socket.io clients with the same session id
|
||||
sockets.in('sess_' + req.sessionID).emit('checkSession', 0);
|
||||
res.status(200).send('');
|
||||
if (req.body.noscript === 'true') {
|
||||
res.redirect(nconf.get('relative_path') + '/');
|
||||
} else {
|
||||
res.status(200).send('');
|
||||
}
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user