From aecd454352405609c94ba617536a9caa174ca6c9 Mon Sep 17 00:00:00 2001 From: Menci Date: Tue, 18 Apr 2017 20:11:54 +0800 Subject: [PATCH] Redirect to last page after login, logout and sign_up --- modules/user.js | 2 +- views/footer.ejs | 2 +- views/header.ejs | 8 ++++---- views/login.ejs | 2 +- views/sign_up.ejs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/user.js b/modules/user.js index dc502c4..565c156 100644 --- a/modules/user.js +++ b/modules/user.js @@ -78,7 +78,7 @@ app.get('/sign_up', async (req, res) => { // Logout app.get('/logout', async (req, res) => { req.session.user_id = null; - res.redirect(syzoj.utils.makeUrl()); + res.redirect(req.query.url || '/'); }); // User page diff --git a/views/footer.ejs b/views/footer.ejs index 998b88b..0f1943b 100644 --- a/views/footer.ejs +++ b/views/footer.ejs @@ -9,7 +9,7 @@ diff --git a/views/header.ejs b/views/header.ejs index 13a3913..bae90d3 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -38,12 +38,12 @@ <% } else { %>
- - +
<% } %> diff --git a/views/login.ejs b/views/login.ejs index 9097113..927fc1a 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -48,7 +48,7 @@ function show_error(error) { $("#error").show(); } function success(session_id) { - window.location.href = "/"; + window.location.href = <%- JSON.stringify(req.query.url || '/') %>; } function login() { password = md5($("#password").val() + "syzoj2_xxx"); diff --git a/views/sign_up.ejs b/views/sign_up.ejs index 03d6156..644b69c 100644 --- a/views/sign_up.ejs +++ b/views/sign_up.ejs @@ -39,7 +39,7 @@ function show_error(error) { } function success() { alert("注册成功!"); - window.location.href = "/"; + window.location.href = <%- JSON.stringify(req.query.url || '/') %>; } function submit() { if ($("#password1").val() != $("#password2").val()) {