From da54a1245bdabf11abed658ea54551d0b94f0e6e Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 20 Oct 2015 20:07:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E5=BD=95=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/decorators.py | 3 ++- contest/decorators.py | 3 ++- contest/test_urls.py | 9 ------- static/src/js/app/oj/account/login.js | 25 ++++++++----------- .../src/oj/account/{oauth.html => sso.html} | 0 5 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 contest/test_urls.py rename template/src/oj/account/{oauth.html => sso.html} (100%) diff --git a/account/decorators.py b/account/decorators.py index 2646c02..b0dbecb 100644 --- a/account/decorators.py +++ b/account/decorators.py @@ -1,4 +1,5 @@ # coding=utf-8 +import urllib import functools from functools import wraps @@ -27,7 +28,7 @@ class BasePermissionDecorator(object): if self.request.is_ajax(): return error_response(u"请先登录") else: - return HttpResponseRedirect("/login/") + return HttpResponseRedirect("/login/?__from=" + urllib.quote(self.request.build_absolute_uri())) def check_permission(self): raise NotImplementedError() diff --git a/contest/decorators.py b/contest/decorators.py index d08783c..2f5e3ba 100644 --- a/contest/decorators.py +++ b/contest/decorators.py @@ -1,4 +1,5 @@ # coding=utf-8 +import urllib from functools import wraps from django.http import HttpResponse, HttpResponseRedirect @@ -30,7 +31,7 @@ def check_user_contest_permission(func): if request.is_ajax(): return error_response(u"请先登录") else: - return HttpResponseRedirect("/login/") + return HttpResponseRedirect("/login/?__from=" + urllib.quote(request.build_absolute_uri())) # kwargs 就包含了 url 里面的参数 if "contest_id" in kwargs: diff --git a/contest/test_urls.py b/contest/test_urls.py deleted file mode 100644 index 234c600..0000000 --- a/contest/test_urls.py +++ /dev/null @@ -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"), -] diff --git a/static/src/js/app/oj/account/login.js b/static/src/js/app/oj/account/login.js index 42b8d68..8e1351d 100644 --- a/static/src/js/app/oj/account/login.js +++ b/static/src/js/app/oj/account/login.js @@ -14,21 +14,18 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c method: "post", success: function (data) { if (!data.code) { - //成功登陆 - var ref = document.referrer; - if (ref) { - // 注册页和本页的来源的跳转回首页,防止死循环 - if (ref.indexOf("register") > -1 || ref.indexOf("login") > -1) { - location.href = "/"; - return; - } - // 判断来源,只有同域下才跳转 - if (ref.split("/")[2].split(":")[0] == location.hostname) { - location.href = ref; - return; - } + function getLocationVal(id){ + var temp = unescape(location.search).split(id+"=")[1] || ""; + return temp.indexOf("&")>=0 ? temp.split("&")[0] : temp; + } + var from = getLocationVal("__from"); + if(from != ""){ + console.log(from); + window.location.href = from; + } + else{ + location.href = "/"; } - location.href = "/"; } else { refresh_captcha(); diff --git a/template/src/oj/account/oauth.html b/template/src/oj/account/sso.html similarity index 100% rename from template/src/oj/account/oauth.html rename to template/src/oj/account/sso.html