diff --git a/account/views.py b/account/views.py index 1304ded..4aa326a 100644 --- a/account/views.py +++ b/account/views.py @@ -36,11 +36,24 @@ class UserLoginAPIView(APIView): else: return serializer_invalid_response(serializer) + @login_required def logout(request): auth.logout(request) return http.HttpResponseRedirect("/") + +def page_jump(request): + if not request.user.is_authenticated(): + return render(request, "oj/index.html") + + try: + if request.META['HTTP_REFERER']: + return render(request, "oj/index.html") + except KeyError: + return http.HttpResponseRedirect('/problems/') + + class UserRegisterAPIView(APIView): def post(self, request): """ diff --git a/oj/urls.py b/oj/urls.py index e9cc880..eda20bb 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -26,7 +26,7 @@ from contest_submission.views import contest_problem_my_submissions_list_page urlpatterns = [ url(r'^install/$', "install.views.install"), - url("^$", TemplateView.as_view(template_name="oj/index.html"), name="index_page"), + url("^$", "account.views.page_jump", name="page_jump_api"), url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/$', TemplateView.as_view(template_name="admin/admin.html"), name="admin_spa_page"), url(r'^admin/contest/$', TemplateView.as_view(template_name="admin/contest/add_contest.html"), diff --git a/template/src/oj/index.html b/template/src/oj/index.html index 41f5d23..4a8edd3 100644 --- a/template/src/oj/index.html +++ b/template/src/oj/index.html @@ -29,6 +29,36 @@ padding: 20px 20px 0 20px; } + #login { + float: right; + position: relative; + height: 30px; + line-height: 64px; + margin-right: 30px; + z-index: 10; + margin-top: 4px; + } + + .login-zone .button:first-child { + margin-right: 5px; + } + + .button { + display: inline-block; + padding: 0 2em; + text-transform: none; + line-height: 2em; + height: 2em; + border-radius: 2em; + border: 1px solid #FFF; + outline: 0; + cursor: pointer; + } + + .button:first-child { + margin-right: 5px; + } + #name { font-size: 45px; margin-right: 20px; @@ -86,8 +116,6 @@ loopBottom: true }); }); - - @@ -100,6 +128,12 @@ 小组 关于 + {% if not request.user.is_authenticated %} +
+ {% endif %}