summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-07-19 19:03:16 +0200
committerTor Andersson <tor@ccxvii.net>2021-07-19 19:12:36 +0200
commit0a31de8125b4050dca9d805423252738c14b982d (patch)
treecb38339de253d8181d341481f0c88211ad43dd46 /server.js
parent76da927e841af2de8c47f2d0a177ecebb9c5b5f8 (diff)
downloadserver-0a31de8125b4050dca9d805423252738c14b982d.tar.gz
Redirect to original URL after being prompted to log in.
Diffstat (limited to 'server.js')
-rw-r--r--server.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/server.js b/server.js
index 7c9de8e..e220d46 100644
--- a/server.js
+++ b/server.js
@@ -268,8 +268,10 @@ function update_last_seen(req) {
}
function must_be_logged_in(req, res, next) {
- if (!req.isAuthenticated())
+ if (!req.isAuthenticated()) {
+ req.session.redirect = req.originalUrl;
return res.redirect('/login');
+ }
if (sql_blacklist_ip.get(req.connection.remoteAddress)[0] !== 0)
return res.redirect('/banned');
if (sql_blacklist_mail.get(req.user.mail)[0] !== 0)
@@ -309,10 +311,14 @@ app.get('/signup', function (req, res) {
app.post('/login',
passport.authenticate('local-login', {
- successRedirect: '/profile',
failureRedirect: '/login',
failureFlash: true
- })
+ }),
+ (req, res) => {
+ let redirect = req.session.redirect || '/profile';
+ delete req.session.redirect;
+ res.redirect(redirect);
+ }
);
app.post('/signup',