mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 13:26:02 +02:00
refactor: simplified utilities API > login rout
Removed continueLogin override in favour of a simpler `redirectAfterLogin` override Use passport to authenticate username and password instead of duplicated logic.
This commit is contained in:
@@ -259,7 +259,7 @@ authenticationController.login = async (req, res, next) => {
|
||||
}
|
||||
}
|
||||
if (isEmailLogin || isUsernameLogin) {
|
||||
(res.locals.continueLogin || continueLogin)(strategy, req, res, next);
|
||||
continueLogin(strategy, req, res, next);
|
||||
} else {
|
||||
errorHandler(req, res, `[[error:wrong-login-type-${loginWith}]]`, 400);
|
||||
}
|
||||
@@ -303,9 +303,7 @@ function continueLogin(strategy, req, res, next) {
|
||||
req.session.passwordExpired = true;
|
||||
|
||||
const code = await user.reset.generate(userData.uid);
|
||||
res.status(200).send({
|
||||
next: `${nconf.get('relative_path')}/reset/${code}`,
|
||||
});
|
||||
(res.locals.redirectAfterLogin || redirectAfterLogin)(req, res, `${nconf.get('relative_path')}/reset/${code}`);
|
||||
} else {
|
||||
delete req.query.lang;
|
||||
await authenticationController.doLogin(req, userData.uid);
|
||||
@@ -319,17 +317,21 @@ function continueLogin(strategy, req, res, next) {
|
||||
destination = `${nconf.get('relative_path')}/`;
|
||||
}
|
||||
|
||||
if (req.body.noscript === 'true') {
|
||||
res.redirect(`${destination}?loggedin`);
|
||||
} else {
|
||||
res.status(200).send({
|
||||
next: destination,
|
||||
});
|
||||
}
|
||||
(res.locals.redirectAfterLogin || redirectAfterLogin)(req, res, destination);
|
||||
}
|
||||
})(req, res, next);
|
||||
}
|
||||
|
||||
function redirectAfterLogin(req, res, destination) {
|
||||
if (req.body.noscript === 'true') {
|
||||
res.redirect(`${destination}?loggedin`);
|
||||
} else {
|
||||
res.status(200).send({
|
||||
next: destination,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
authenticationController.doLogin = async function (req, uid) {
|
||||
if (!uid) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user