2015-05-28 17:25:52 +02:00
|
|
|
from django.conf.urls import url
|
2014-01-14 16:43:27 +01:00
|
|
|
from django.contrib import admin
|
2014-08-12 16:54:42 +02:00
|
|
|
from django.contrib.auth import views
|
2010-09-10 21:38:57 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2015-01-28 13:35:27 +01:00
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
2015-05-19 11:10:04 +02:00
|
|
|
from django.contrib.auth.urls import urlpatterns as auth_urlpatterns
|
2011-05-31 17:19:19 +02:00
|
|
|
from django.contrib.messages.api import info
|
2015-01-28 13:35:27 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2014-12-14 10:17:18 +01:00
|
|
|
from django.shortcuts import render
|
2015-01-28 13:35:27 +01:00
|
|
|
from django.template import RequestContext, Template
|
2013-04-09 23:31:58 +02:00
|
|
|
from django.urls import reverse_lazy
|
2011-03-17 09:07:40 +01:00
|
|
|
from django.views.decorators.cache import never_cache
|
2009-05-04 09:05:44 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2013-02-24 00:25:05 +01:00
|
|
|
class CustomRequestAuthenticationForm(AuthenticationForm):
|
|
|
|
def __init__(self, request, *args, **kwargs):
|
|
|
|
assert isinstance(request, HttpRequest)
|
2017-01-21 14:13:44 +01:00
|
|
|
super().__init__(request, *args, **kwargs)
|
2013-02-24 00:25:05 +01:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-03-17 09:07:40 +01:00
|
|
|
@never_cache
|
2009-05-04 09:05:44 +02:00
|
|
|
def remote_user_auth_view(request):
|
|
|
|
"Dummy view for remote user tests"
|
|
|
|
t = Template("Username is {{ user }}.")
|
|
|
|
c = RequestContext(request, {})
|
|
|
|
return HttpResponse(t.render(c))
|
2009-04-01 19:02:32 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-04-02 10:44:47 +02:00
|
|
|
def auth_processor_no_attr_access(request):
|
2014-12-14 10:17:18 +01:00
|
|
|
render(request, 'context_processors/auth_attrs_no_access.html')
|
2011-04-02 10:44:47 +02:00
|
|
|
# *After* rendering, we check whether the session was accessed
|
2014-12-14 10:17:18 +01:00
|
|
|
return render(request,
|
|
|
|
'context_processors/auth_attrs_test_access.html',
|
|
|
|
{'session_accessed': request.session.accessed})
|
2011-04-02 10:44:47 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-04-02 10:44:47 +02:00
|
|
|
def auth_processor_attr_access(request):
|
2014-12-14 10:17:18 +01:00
|
|
|
render(request, 'context_processors/auth_attrs_access.html')
|
|
|
|
return render(request,
|
|
|
|
'context_processors/auth_attrs_test_access.html',
|
|
|
|
{'session_accessed': request.session.accessed})
|
2011-04-02 10:44:47 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-04-02 10:44:47 +02:00
|
|
|
def auth_processor_user(request):
|
2014-12-14 10:17:18 +01:00
|
|
|
return render(request, 'context_processors/auth_attrs_user.html')
|
2011-04-02 10:44:47 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-04-02 10:44:47 +02:00
|
|
|
def auth_processor_perms(request):
|
2014-12-14 10:17:18 +01:00
|
|
|
return render(request, 'context_processors/auth_attrs_perms.html')
|
2011-04-02 10:44:47 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2012-09-30 17:13:23 +02:00
|
|
|
def auth_processor_perm_in_perms(request):
|
2014-12-14 10:17:18 +01:00
|
|
|
return render(request, 'context_processors/auth_attrs_perm_in_perms.html')
|
2012-09-30 17:13:23 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-04-02 10:44:47 +02:00
|
|
|
def auth_processor_messages(request):
|
2011-05-31 17:19:19 +02:00
|
|
|
info(request, "Message 1")
|
2014-12-14 10:17:18 +01:00
|
|
|
return render(request, 'context_processors/auth_attrs_messages.html')
|
2011-04-02 10:44:47 +02:00
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2011-04-02 10:44:47 +02:00
|
|
|
def userpage(request):
|
|
|
|
pass
|
|
|
|
|
2013-10-31 16:42:28 +01:00
|
|
|
|
2017-03-07 19:43:17 +01:00
|
|
|
uid_token = '(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})'
|
|
|
|
|
2009-04-01 19:02:32 +02:00
|
|
|
# special urls for auth test cases
|
2015-05-19 11:10:04 +02:00
|
|
|
urlpatterns = auth_urlpatterns + [
|
2016-05-15 17:28:00 +02:00
|
|
|
url(r'^logout/custom_query/$', views.LogoutView.as_view(redirect_field_name='follow')),
|
|
|
|
url(r'^logout/next_page/$', views.LogoutView.as_view(next_page='/somewhere/')),
|
|
|
|
url(r'^logout/next_page/named/$', views.LogoutView.as_view(next_page='password_reset')),
|
2016-07-27 01:10:08 +02:00
|
|
|
url(r'^logout/allowed_hosts/$', views.LogoutView.as_view(success_url_allowed_hosts={'otherserver'})),
|
2014-04-02 02:46:34 +02:00
|
|
|
url(r'^remote_user/$', remote_user_auth_view),
|
2013-04-09 23:31:58 +02:00
|
|
|
|
|
|
|
url(r'^password_reset_from_email/$',
|
|
|
|
views.PasswordResetView.as_view(from_email='staffmember@example.com')),
|
|
|
|
url(r'^password_reset_extra_email_context/$',
|
|
|
|
views.PasswordResetView.as_view(extra_email_context=dict(greeting='Hello!'))),
|
|
|
|
url(r'^password_reset/custom_redirect/$',
|
|
|
|
views.PasswordResetView.as_view(success_url='/custom/')),
|
|
|
|
url(r'^password_reset/custom_redirect/named/$',
|
|
|
|
views.PasswordResetView.as_view(success_url=reverse_lazy('password_reset'))),
|
|
|
|
url(r'^password_reset/html_email_template/$',
|
|
|
|
views.PasswordResetView.as_view(
|
|
|
|
html_email_template_name='registration/html_password_reset_email.html'
|
|
|
|
)),
|
2017-03-07 19:43:17 +01:00
|
|
|
url(r'^reset/custom/{}/$'.format(uid_token),
|
2013-04-09 23:31:58 +02:00
|
|
|
views.PasswordResetConfirmView.as_view(success_url='/custom/')),
|
2017-03-07 19:43:17 +01:00
|
|
|
url(r'^reset/custom/named/{}/$'.format(uid_token),
|
2013-04-09 23:31:58 +02:00
|
|
|
views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('password_reset'))),
|
2017-03-07 19:43:17 +01:00
|
|
|
url(r'^reset/post_reset_login/{}/$'.format(uid_token),
|
2016-07-28 00:33:07 +02:00
|
|
|
views.PasswordResetConfirmView.as_view(post_reset_login=True)),
|
2017-03-08 01:52:26 +01:00
|
|
|
url(
|
|
|
|
r'^reset/post_reset_login_custom_backend/{}/$'.format(uid_token),
|
|
|
|
views.PasswordResetConfirmView.as_view(
|
|
|
|
post_reset_login=True,
|
|
|
|
post_reset_login_backend='django.contrib.auth.backends.AllowAllUsersModelBackend',
|
|
|
|
),
|
|
|
|
),
|
2013-04-09 23:31:58 +02:00
|
|
|
url(r'^password_change/custom/$',
|
|
|
|
views.PasswordChangeView.as_view(success_url='/custom/')),
|
|
|
|
url(r'^password_change/custom/named/$',
|
|
|
|
views.PasswordChangeView.as_view(success_url=reverse_lazy('password_reset'))),
|
|
|
|
url(r'^login_required/$', login_required(views.PasswordResetView.as_view())),
|
|
|
|
url(r'^login_required_login_url/$', login_required(views.PasswordResetView.as_view(), login_url='/somewhere/')),
|
2014-04-02 02:46:34 +02:00
|
|
|
|
|
|
|
url(r'^auth_processor_no_attr_access/$', auth_processor_no_attr_access),
|
|
|
|
url(r'^auth_processor_attr_access/$', auth_processor_attr_access),
|
|
|
|
url(r'^auth_processor_user/$', auth_processor_user),
|
|
|
|
url(r'^auth_processor_perms/$', auth_processor_perms),
|
|
|
|
url(r'^auth_processor_perm_in_perms/$', auth_processor_perm_in_perms),
|
|
|
|
url(r'^auth_processor_messages/$', auth_processor_messages),
|
2016-05-15 17:28:00 +02:00
|
|
|
url(r'^custom_request_auth_login/$',
|
|
|
|
views.LoginView.as_view(authentication_form=CustomRequestAuthenticationForm)),
|
2011-04-02 10:44:47 +02:00
|
|
|
url(r'^userpage/(.+)/$', userpage, name="userpage"),
|
2016-05-15 17:28:00 +02:00
|
|
|
url(r'^login/redirect_authenticated_user_default/$', views.LoginView.as_view()),
|
|
|
|
url(r'^login/redirect_authenticated_user/$',
|
|
|
|
views.LoginView.as_view(redirect_authenticated_user=True)),
|
2016-07-27 01:10:08 +02:00
|
|
|
url(r'^login/allowed_hosts/$',
|
|
|
|
views.LoginView.as_view(success_url_allowed_hosts={'otherserver'})),
|
2014-01-14 16:43:27 +01:00
|
|
|
|
|
|
|
# This line is only required to render the password reset with is_admin=True
|
2015-05-28 17:25:52 +02:00
|
|
|
url(r'^admin/', admin.site.urls),
|
2014-04-02 02:46:34 +02:00
|
|
|
]
|