mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 13:59:25 +00:00
Added redirect_to to login page when auth forces re-authentication
This commit is contained in:
2
app.js
2
app.js
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user