|
|
@ -248,31 +248,29 @@ authenticationController.login = async (req, res, next) => {
|
|
|
|
|
|
|
|
|
|
|
|
const loginWith = meta.config.allowLoginWith || 'username-email';
|
|
|
|
const loginWith = meta.config.allowLoginWith || 'username-email';
|
|
|
|
req.body.username = req.body.username.trim();
|
|
|
|
req.body.username = req.body.username.trim();
|
|
|
|
|
|
|
|
const errorHandler = res.locals.noScriptErrors || helpers.noScriptErrors;
|
|
|
|
plugins.hooks.fire('filter:login.check', { req: req, res: res, userData: req.body }, (err) => {
|
|
|
|
try {
|
|
|
|
if (err) {
|
|
|
|
await plugins.hooks.fire('filter:login.check', { req: req, res: res, userData: req.body });
|
|
|
|
return (res.locals.noScriptErrors || helpers.noScriptErrors)(req, res, err.message, 403);
|
|
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
return errorHandler(req, res, err.message, 403);
|
|
|
|
if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.includes('email')) {
|
|
|
|
}
|
|
|
|
async.waterfall([
|
|
|
|
try {
|
|
|
|
function (next) {
|
|
|
|
const isEmailLogin = loginWith.includes('email') && req.body.username && utils.isEmailValid(req.body.username);
|
|
|
|
user.getUsernameByEmail(req.body.username, next);
|
|
|
|
const isUsernameLogin = loginWith.includes('username') && !validator.isEmail(req.body.username);
|
|
|
|
},
|
|
|
|
if (isEmailLogin) {
|
|
|
|
function (username, next) {
|
|
|
|
const username = await user.getUsernameByEmail(req.body.username);
|
|
|
|
if (username !== '[[global:guest]]') {
|
|
|
|
if (username !== '[[global:guest]]') {
|
|
|
|
req.body.username = username;
|
|
|
|
req.body.username = username;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
(res.locals.continueLogin || continueLogin)(strategy, req, res, next);
|
|
|
|
if (isEmailLogin || isUsernameLogin) {
|
|
|
|
},
|
|
|
|
|
|
|
|
], next);
|
|
|
|
|
|
|
|
} else if (loginWith.includes('username') && !validator.isEmail(req.body.username)) {
|
|
|
|
|
|
|
|
(res.locals.continueLogin || continueLogin)(strategy, req, res, next);
|
|
|
|
(res.locals.continueLogin || continueLogin)(strategy, req, res, next);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
err = `[[error:wrong-login-type-${loginWith}]]`;
|
|
|
|
errorHandler(req, res, `[[error:wrong-login-type-${loginWith}]]`, 400);
|
|
|
|
(res.locals.noScriptErrors || helpers.noScriptErrors)(req, res, err, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
return errorHandler(req, res, err.message, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function continueLogin(strategy, req, res, next) {
|
|
|
|
function continueLogin(strategy, req, res, next) {
|
|
|
|