Skip to content

Commit

Permalink
N21-1273 sonar duplications fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns committed Oct 12, 2023
1 parent c7c870f commit 6feb5c9
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ router.post('/login/email', async (req, res) => {
password,
};

const result = await authHelper.loginUser(req, res, 'local', payload, redirect, 'Email');
const loginEmailRedirect = await authHelper.loginUser(req, res, 'local', payload, redirect, 'Email');

res.redirect(result.redirect);
res.redirect(loginEmailRedirect.redirect);
});

router.get('/login/email', (req, res) => {
Expand Down Expand Up @@ -148,9 +148,9 @@ router.post('/login/ldap', async (req, res) => {
schoolId,
};

const result = await authHelper.loginUser(req, res, 'ldap', payload, redirect, 'LDAP');
const loginLdapRedirect = await authHelper.loginUser(req, res, 'ldap', payload, redirect, 'LDAP');

res.redirect(result.redirect);
res.redirect(loginLdapRedirect.redirect);
});

router.get('/login/ldap', (req, res) => {
Expand All @@ -172,7 +172,7 @@ const redirectOAuth2Authentication = async (req, res, systemId, migration, redir
let system;
try {
system = await api(req, { version: 'v3' })
.get(`/systems/public/${systemId}`);
.get(`/systems/public/${systemId}`);
} catch (error) {
return authHelper.handleLoginError(req, res, error.error, redirect);
}
Expand Down Expand Up @@ -306,12 +306,12 @@ const determineRedirectUrl = (req) => {

const filterSchoolsWithLdapLogin = (schools) => schools
// eslint-disable-next-line max-len
.filter((school) => school.systems.some((system) => system.type === 'ldap' && !system.oauthConfig));
.filter((school) => school.systems.some((system) => system.type === 'ldap' && !system.oauthConfig));

async function getOauthSystems(req) {
return api(req, { version: 'v3' })
.get('/systems/public?onlyOauth=true')
.catch((err) => logger.error('error loading oauth system list', formatError(err)));
.get('/systems/public?onlyOauth=true')
.catch((err) => logger.error('error loading oauth system list', formatError(err)));
}

router.all('/', async (req, res, next) => {
Expand Down Expand Up @@ -398,26 +398,26 @@ const renderLogin = async (req, res) => {

router.get('/loginRedirect', (req, res, next) => {
authHelper.isAuthenticated(req)
.then((isAuthenticated) => {
if (isAuthenticated) {
redirectAuthenticated(req, res);
} else {
res.redirect('/login');
}
})
.catch(next);
.then((isAuthenticated) => {
if (isAuthenticated) {
redirectAuthenticated(req, res);
} else {
res.redirect('/login');
}
})
.catch(next);
});

router.all('/login/', async (req, res, next) => {
authHelper.isAuthenticated(req)
.then(async (isAuthenticated) => {
if (isAuthenticated) {
redirectAuthenticated(req, res);
} else {
await renderLogin(req, res);
}
})
.catch(next);
.then(async (isAuthenticated) => {
if (isAuthenticated) {
redirectAuthenticated(req, res);
} else {
await renderLogin(req, res);
}
})
.catch(next);
});

router.all('/login/superhero/', async (req, res, next) => {
Expand All @@ -429,7 +429,7 @@ router.all('/login/superhero/', async (req, res, next) => {
};

await renderLogin(req, res)
.catch(next);
.catch(next);
});

router.get('/login/success', authHelper.authChecker, async (req, res) => {
Expand All @@ -445,11 +445,11 @@ router.get('/login/success', authHelper.authChecker, async (req, res) => {
haveBeenUpdated,
consentStatus,
} = await api(req)
.get(`/consents/${user._id}/check/`, {
qs: {
simple: true,
},
});
.get(`/consents/${user._id}/check/`, {
qs: {
simple: true,
},
});

if (consentStatus === 'ok' && haveBeenUpdated === false && (user.preferences || {}).firstLogin) {
return res.redirect(redirectUrl);
Expand Down Expand Up @@ -502,17 +502,17 @@ const sessionDestroyer = (req, res, rej, next) => {

router.get('/logout/', (req, res, next) => {
api(req)
.del('/authentication') // async, ignore result
.catch((err) => {
logger.error('error during logout.', formatError(err));
});
.del('/authentication') // async, ignore result
.catch((err) => {
logger.error('error during logout.', formatError(err));
});
return authHelper.clearCookie(req, res, sessionDestroyer)
// eslint-disable-next-line prefer-template, no-return-assign
.then(() => {
res.statusCode = 307;
res.redirect('/');
})
.catch(next);
.then(() => {
res.statusCode = 307;
res.redirect('/');
})
.catch(next);
});

module.exports = router;

0 comments on commit 6feb5c9

Please sign in to comment.