Skip to content

Commit

Permalink
Accept Merge Request QingdaoU#232 实现根据用户登录状态的来确定首页页面跳转问题 : (hohoTT-de…
Browse files Browse the repository at this point in the history
…v -> dev)

Merge Request: 实现根据用户登录状态的来确定首页页面跳转问题
Created By: @hohoTT
Accepted By: @virusdefender
URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/232
  • Loading branch information
virusdefender committed Sep 14, 2015
2 parents 4cf6187 + 32a07d5 commit 74f9c29
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
13 changes: 13 additions & 0 deletions account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ def post(self, request):
else:
return serializer_invalid_response(serializer)


@login_required
def logout(request):
auth.logout(request)
return http.HttpResponseRedirect("/")


def index_page(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):
"""
Expand Down
2 changes: 1 addition & 1 deletion oj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

urlpatterns = [
url(r'^install/$', "install.views.install"),
url("^$", TemplateView.as_view(template_name="oj/index.html"), name="index_page"),
url("^$", "account.views.index_page", name="index_page"),
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"),
Expand Down
38 changes: 36 additions & 2 deletions template/src/oj/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,8 +116,6 @@
loopBottom: true
});
});


</script>

</head>
Expand All @@ -100,6 +128,12 @@
<a href="/groups/">小组</a>&nbsp;&nbsp;
<a href="/about/">关于</a>

{% if not request.user.is_authenticated %}
<div id="login">
<a href="/login/" class="login button">登录</a>
<a href="/register/" class="register button">注册</a>
</div>
{% endif %}

</div>

Expand Down

0 comments on commit 74f9c29

Please sign in to comment.