feat: adding filter:login.check and loginFormEntry[] for the filter:login.build hook (#7861)

* adding filter:login.check and loginFormEntry[] for the filter:login.build hook, related to nodebb-plugin-spam-be-gone/issues/32

* do not exceed 50 lines per function

* spam-be-gone@0.6.4
v1.18.x
Aziz Khoury 5 years ago committed by Julian Lam
parent 310039e875
commit 94810fd637

@ -201,22 +201,27 @@ authenticationController.login = function (req, res, next) {
var loginWith = meta.config.allowLoginWith || 'username-email';
req.body.username = req.body.username.trim();
if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.includes('email')) {
async.waterfall([
function (next) {
user.getUsernameByEmail(req.body.username, next);
},
function (username, next) {
req.body.username = username || req.body.username;
continueLogin(req, res, next);
},
], next);
} else if (loginWith.includes('username') && !validator.isEmail(req.body.username)) {
continueLogin(req, res, next);
} else {
var err = '[[error:wrong-login-type-' + loginWith + ']]';
helpers.noScriptErrors(req, res, err, 500);
}
plugins.fireHook('filter:login.check', { req: req, res: res, userData: req.body }, (err) => {
if (err) {
return helpers.noScriptErrors(req, res, err.message, 403);
}
if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.includes('email')) {
async.waterfall([
function (next) {
user.getUsernameByEmail(req.body.username, next);
},
function (username, next) {
req.body.username = username || req.body.username;
continueLogin(req, res, next);
},
], next);
} else if (loginWith.includes('username') && !validator.isEmail(req.body.username)) {
continueLogin(req, res, next);
} else {
err = '[[error:wrong-login-type-' + loginWith + ']]';
helpers.noScriptErrors(req, res, err, 500);
}
});
};
function continueLogin(req, res, next) {

@ -96,7 +96,7 @@ Controllers.reset = function (req, res, next) {
};
Controllers.login = function (req, res, next) {
var data = {};
var data = { loginFormEntry: [] };
var loginStrategies = require('../routes/authentication').getLoginStrategies();
var registrationType = meta.config.registrationType || 'normal';
var allowLoginWith = (meta.config.allowLoginWith || 'username-email');

Loading…
Cancel
Save