增加登录之后的重定向

This commit is contained in:
virusdefender
2015-10-20 20:07:35 +08:00
parent 190565da88
commit da54a1245b
5 changed files with 15 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
# coding=utf-8 # coding=utf-8
import urllib
import functools import functools
from functools import wraps from functools import wraps
@@ -27,7 +28,7 @@ class BasePermissionDecorator(object):
if self.request.is_ajax(): if self.request.is_ajax():
return error_response(u"请先登录") return error_response(u"请先登录")
else: else:
return HttpResponseRedirect("/login/") return HttpResponseRedirect("/login/?__from=" + urllib.quote(self.request.build_absolute_uri()))
def check_permission(self): def check_permission(self):
raise NotImplementedError() raise NotImplementedError()

View File

@@ -1,4 +1,5 @@
# coding=utf-8 # coding=utf-8
import urllib
from functools import wraps from functools import wraps
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
@@ -30,7 +31,7 @@ def check_user_contest_permission(func):
if request.is_ajax(): if request.is_ajax():
return error_response(u"请先登录") return error_response(u"请先登录")
else: else:
return HttpResponseRedirect("/login/") return HttpResponseRedirect("/login/?__from=" + urllib.quote(request.build_absolute_uri()))
# kwargs 就包含了 url 里面的参数 # kwargs 就包含了 url 里面的参数
if "contest_id" in kwargs: if "contest_id" in kwargs:

View File

@@ -1,9 +0,0 @@
# coding=utf-8
from django.conf.urls import include, url
from django.views.generic import TemplateView
urlpatterns = [
url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"),
]

View File

@@ -14,21 +14,18 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c
method: "post", method: "post",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
//成功登陆 function getLocationVal(id){
var ref = document.referrer; var temp = unescape(location.search).split(id+"=")[1] || "";
if (ref) { return temp.indexOf("&")>=0 ? temp.split("&")[0] : temp;
// 注册页和本页的来源的跳转回首页,防止死循环 }
if (ref.indexOf("register") > -1 || ref.indexOf("login") > -1) { var from = getLocationVal("__from");
if(from != ""){
console.log(from);
window.location.href = from;
}
else{
location.href = "/"; location.href = "/";
return;
} }
// 判断来源,只有同域下才跳转
if (ref.split("/")[2].split(":")[0] == location.hostname) {
location.href = ref;
return;
}
}
location.href = "/";
} }
else { else {
refresh_captcha(); refresh_captcha();