1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 20:59:30 +00:00

Added redirect_to to login page when auth forces re-authentication

This commit is contained in:
2022-04-12 00:34:32 +00:00
parent 26f0a6e2cc
commit 6406cd5a5c
3 changed files with 9 additions and 2 deletions

2
app.js
View File

@@ -106,7 +106,7 @@ async function main() {
const path = `/${req.path.split('/')?.[1] ?? ''}`;
if (!allowed.includes(path) && !req.session.authenticated)
return res.redirect('/login');
return res.redirect(`/login?redirect_to=${req.path}`);
next();
});

View File

@@ -21,7 +21,8 @@ router.get('/login', (req, res) => {
return res.redirect('/admin');
return res.render('login', {
title: 'Stratos - Login'
title: 'Stratos - Login',
redirect_to: req.query?.redirect_to
});
});
@@ -79,6 +80,10 @@ router.post('/login', async (req, res) => {
if (await u.verifyPassword(fields.get('password'))) {
u.login(req);
if (fields.get('redirectTo').length > 0)
return res.redirect(fields.get('redirectTo'));
return res.redirect('/admin');
}

View File

@@ -5,6 +5,8 @@
<input type='email' id='email' name='email' placeholder='Email Address' required/>
<input type='password' id='password' name='password' placeholder='Password' required/>
<input type='hidden' id='redirectTo' name='redirectTo' value='{{redirect_to}}' required/>
<input type='submit' class='btn btn--primary btn--full' value='Log In'/>
</form>
<a href='/register'>Not got an account yet? Sign up</a>