зеркало из https://github.com/mozilla/treeherder.git
Bug 1160111 - Create login page for login_required
The login_required decorator redirects unauthenticated users to settings.LOGIN_URL, adding a `next` querystring parameter to it. This parameter is then passed to the browserid login button so that the user can be sent back to the original page after a successful authentication.
This commit is contained in:
Родитель
28d5708d7f
Коммит
01fab0efe9
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -0,0 +1,29 @@
|
|||
{% load browserid static %}
|
||||
<html>
|
||||
<head>
|
||||
{% browserid_css %}
|
||||
<link rel="stylesheet" href="{% static "webapp/css/bootstrap.min.css" %}">
|
||||
</head>
|
||||
<body>
|
||||
{% browserid_info %}
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Treeherder Login</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p class="text-center">
|
||||
{% if user.is_authenticated %}
|
||||
Current user: {{ user.email }}
|
||||
{% browserid_logout text='Logout' %}
|
||||
{% else %}
|
||||
{% browserid_login text='Login with email' color='dark' next=next %}
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="{% static "webapp/js/jquery-2.1.4.min.js" %}"></script>
|
||||
{% browserid_js %}
|
||||
</body>
|
||||
</html>
|
|
@ -1,17 +1,19 @@
|
|||
from django.conf.urls import include, patterns, url
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
from django_browserid.admin import site as browserid_admin
|
||||
|
||||
from treeherder.embed import urls as embed_urls
|
||||
|
||||
from .api import urls as api_urls
|
||||
from .views import LoginView
|
||||
|
||||
browserid_admin.copy_registry(admin.site)
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^api/', include(api_urls)),
|
||||
url(r'^embed/', include(embed_urls)),
|
||||
url(r'^admin/', include(browserid_admin.urls)),
|
||||
url(r'^docs/', include('rest_framework_swagger.urls')),
|
||||
url(r'', include('django_browserid.urls')),
|
||||
)
|
||||
urlpatterns = [
|
||||
url(r'^api/', include(api_urls)),
|
||||
url(r'^accounts/login/$', LoginView.as_view(), name='persona_login'),
|
||||
url(r'^embed/', include(embed_urls)),
|
||||
url(r'^admin/', include(browserid_admin.urls)),
|
||||
url(r'^docs/', include('rest_framework_swagger.urls')),
|
||||
url(r'', include('django_browserid.urls')),
|
||||
]
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
class LoginView(TemplateView):
|
||||
template_name = 'webapp/persona_login.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(LoginView, self).get_context_data(**kwargs)
|
||||
# This is the page the user will be redirected after login.
|
||||
# Django_browserid will validate this so it's safe to pass it through.
|
||||
context['next'] = self.request.GET.get('next')
|
||||
return context
|
Загрузка…
Ссылка в новой задаче