Browse Source

Redirect to last page after login, logout and sign_up

pull/6/head
Menci 8 years ago
parent
commit
aecd454352
  1. 2
      modules/user.js
  2. 2
      views/footer.ejs
  3. 8
      views/header.ejs
  4. 2
      views/login.ejs
  5. 2
      views/sign_up.ejs

2
modules/user.js

@ -78,7 +78,7 @@ app.get('/sign_up', async (req, res) => {
// Logout // Logout
app.get('/logout', async (req, res) => { app.get('/logout', async (req, res) => {
req.session.user_id = null; req.session.user_id = null;
res.redirect(syzoj.utils.makeUrl()); res.redirect(req.query.url || '/');
}); });
// User page // User page

2
views/footer.ejs

@ -9,7 +9,7 @@
<script src="//cdn.bootcss.com/Chart.js/2.4.0/Chart.bundle.min.js"></script> <script src="//cdn.bootcss.com/Chart.js/2.4.0/Chart.bundle.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$("#logout").click(function () { $("#logout").click(function () {
window.location.href = "/logout"; window.location.href = <%- JSON.stringify(syzoj.utils.makeUrl(['logout'], { url: req.originalUrl })) %>;
}); });
</script> </script>
</body> </body>

8
views/header.ejs

@ -38,12 +38,12 @@
</a> </a>
<% } else { %> <% } else { %>
<div class="item"> <div class="item">
<div class="ui button" style="margin-right: 0.5em" onclick="window.location.href='/login'"> <a class="ui button" style="margin-right: 0.5em; " href="<%= syzoj.utils.makeUrl(['login'], { url: req.originalUrl }) %>">
登录 登录
</div> </a>
<div class="ui primary button" onclick="window.location.href='/sign_up'"> <a class="ui primary button" href="<%= syzoj.utils.makeUrl(['sign_up'], { url: req.originalUrl }) %>">
注册 注册
</div> </a>
</div> </div>
<% } %> <% } %>
</div> </div>

2
views/login.ejs

@ -48,7 +48,7 @@ function show_error(error) {
$("#error").show(); $("#error").show();
} }
function success(session_id) { function success(session_id) {
window.location.href = "/"; window.location.href = <%- JSON.stringify(req.query.url || '/') %>;
} }
function login() { function login() {
password = md5($("#password").val() + "syzoj2_xxx"); password = md5($("#password").val() + "syzoj2_xxx");

2
views/sign_up.ejs

@ -39,7 +39,7 @@ function show_error(error) {
} }
function success() { function success() {
alert("注册成功!"); alert("注册成功!");
window.location.href = "/"; window.location.href = <%- JSON.stringify(req.query.url || '/') %>;
} }
function submit() { function submit() {
if ($("#password1").val() != $("#password2").val()) { if ($("#password1").val() != $("#password2").val()) {

Loading…
Cancel
Save