2014-01-14 15:43:27 +00:00
|
|
|
from django.contrib import admin
|
2014-08-12 14:54:42 +00:00
|
|
|
from django.contrib.auth import views
|
2018-03-12 15:48:46 +00:00
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
2015-05-19 09:10:04 +00:00
|
|
|
from django.contrib.auth.urls import urlpatterns as auth_urlpatterns
|
2011-05-31 15:19:19 +00:00
|
|
|
from django.contrib.messages.api import info
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2014-12-14 09:17:18 +00:00
|
|
|
from django.shortcuts import render
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.template import RequestContext, Template
|
2018-12-07 22:52:28 +00:00
|
|
|
from django.urls import path, re_path, reverse_lazy
|
2011-03-17 08:07:40 +00:00
|
|
|
from django.views.decorators.cache import never_cache
|
2016-08-14 20:42:49 +00:00
|
|
|
from django.views.i18n import set_language
|
2009-05-04 07:05:44 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2013-02-23 23:25:05 +00:00
|
|
|
class CustomRequestAuthenticationForm(AuthenticationForm):
|
|
|
|
def __init__(self, request, *args, **kwargs):
|
|
|
|
assert isinstance(request, HttpRequest)
|
2017-01-21 13:13:44 +00:00
|
|
|
super().__init__(request, *args, **kwargs)
|
2013-02-23 23:25:05 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-03-17 08:07:40 +00:00
|
|
|
@never_cache
|
2009-05-04 07:05:44 +00: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 17:02:32 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
def auth_processor_no_attr_access(request):
|
2014-12-14 09:17:18 +00:00
|
|
|
render(request, 'context_processors/auth_attrs_no_access.html')
|
2011-04-02 08:44:47 +00:00
|
|
|
# *After* rendering, we check whether the session was accessed
|
2014-12-14 09:17:18 +00:00
|
|
|
return render(request,
|
|
|
|
'context_processors/auth_attrs_test_access.html',
|
|
|
|
{'session_accessed': request.session.accessed})
|
2011-04-02 08:44:47 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
def auth_processor_attr_access(request):
|
2014-12-14 09:17:18 +00: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 08:44:47 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
def auth_processor_user(request):
|
2014-12-14 09:17:18 +00:00
|
|
|
return render(request, 'context_processors/auth_attrs_user.html')
|
2011-04-02 08:44:47 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
def auth_processor_perms(request):
|
2014-12-14 09:17:18 +00:00
|
|
|
return render(request, 'context_processors/auth_attrs_perms.html')
|
2011-04-02 08:44:47 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2012-09-30 15:13:23 +00:00
|
|
|
def auth_processor_perm_in_perms(request):
|
2014-12-14 09:17:18 +00:00
|
|
|
return render(request, 'context_processors/auth_attrs_perm_in_perms.html')
|
2012-09-30 15:13:23 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
def auth_processor_messages(request):
|
2011-05-31 15:19:19 +00:00
|
|
|
info(request, "Message 1")
|
2014-12-14 09:17:18 +00:00
|
|
|
return render(request, 'context_processors/auth_attrs_messages.html')
|
2011-04-02 08:44:47 +00:00
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
def userpage(request):
|
|
|
|
pass
|
|
|
|
|
2013-10-31 15:42:28 +00:00
|
|
|
|
2018-03-12 15:48:46 +00:00
|
|
|
@permission_required('unknown.permission')
|
|
|
|
def permission_required_redirect(request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@permission_required('unknown.permission', raise_exception=True)
|
|
|
|
def permission_required_exception(request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@permission_required('unknown.permission', raise_exception=True)
|
|
|
|
def login_and_permission_required_exception(request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2009-04-01 17:02:32 +00:00
|
|
|
# special urls for auth test cases
|
2015-05-19 09:10:04 +00:00
|
|
|
urlpatterns = auth_urlpatterns + [
|
2018-12-07 22:52:28 +00:00
|
|
|
path('logout/custom_query/', views.LogoutView.as_view(redirect_field_name='follow')),
|
|
|
|
path('logout/next_page/', views.LogoutView.as_view(next_page='/somewhere/')),
|
|
|
|
path('logout/next_page/named/', views.LogoutView.as_view(next_page='password_reset')),
|
|
|
|
path('logout/allowed_hosts/', views.LogoutView.as_view(success_url_allowed_hosts={'otherserver'})),
|
|
|
|
path('remote_user/', remote_user_auth_view),
|
|
|
|
|
|
|
|
path('password_reset_from_email/', views.PasswordResetView.as_view(from_email='staffmember@example.com')),
|
|
|
|
path(
|
|
|
|
'password_reset_extra_email_context/',
|
2019-05-23 12:22:41 +00:00
|
|
|
views.PasswordResetView.as_view(
|
|
|
|
extra_email_context={'greeting': 'Hello!', 'domain': 'custom.example.com'},
|
|
|
|
),
|
|
|
|
),
|
2018-12-07 22:52:28 +00:00
|
|
|
path(
|
|
|
|
'password_reset/custom_redirect/',
|
2013-04-09 21:31:58 +00:00
|
|
|
views.PasswordResetView.as_view(success_url='/custom/')),
|
2018-12-07 22:52:28 +00:00
|
|
|
path(
|
|
|
|
'password_reset/custom_redirect/named/',
|
2013-04-09 21:31:58 +00:00
|
|
|
views.PasswordResetView.as_view(success_url=reverse_lazy('password_reset'))),
|
2018-12-07 22:52:28 +00:00
|
|
|
path(
|
|
|
|
'password_reset/html_email_template/',
|
2013-04-09 21:31:58 +00:00
|
|
|
views.PasswordResetView.as_view(
|
|
|
|
html_email_template_name='registration/html_password_reset_email.html'
|
|
|
|
)),
|
2020-02-12 09:29:32 +00:00
|
|
|
path(
|
|
|
|
'reset/custom/<uidb64>/<token>/',
|
2018-12-07 22:52:28 +00:00
|
|
|
views.PasswordResetConfirmView.as_view(success_url='/custom/'),
|
|
|
|
),
|
2020-02-12 09:29:32 +00:00
|
|
|
path(
|
|
|
|
'reset/custom/named/<uidb64>/<token>/',
|
2018-12-07 22:52:28 +00:00
|
|
|
views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('password_reset')),
|
|
|
|
),
|
2020-02-12 09:29:32 +00:00
|
|
|
path(
|
|
|
|
'reset/custom/token/<uidb64>/<token>/',
|
2019-05-23 12:18:49 +00:00
|
|
|
views.PasswordResetConfirmView.as_view(reset_url_token='set-passwordcustom'),
|
|
|
|
),
|
2020-02-12 09:29:32 +00:00
|
|
|
path(
|
|
|
|
'reset/post_reset_login/<uidb64>/<token>/',
|
2018-12-07 22:52:28 +00:00
|
|
|
views.PasswordResetConfirmView.as_view(post_reset_login=True),
|
|
|
|
),
|
2020-02-12 09:29:32 +00:00
|
|
|
path(
|
|
|
|
'reset/post_reset_login_custom_backend/<uidb64>/<token>/',
|
2017-03-08 00:52:26 +00:00
|
|
|
views.PasswordResetConfirmView.as_view(
|
|
|
|
post_reset_login=True,
|
|
|
|
post_reset_login_backend='django.contrib.auth.backends.AllowAllUsersModelBackend',
|
|
|
|
),
|
|
|
|
),
|
2018-12-07 22:52:28 +00:00
|
|
|
path('password_change/custom/',
|
|
|
|
views.PasswordChangeView.as_view(success_url='/custom/')),
|
|
|
|
path('password_change/custom/named/',
|
|
|
|
views.PasswordChangeView.as_view(success_url=reverse_lazy('password_reset'))),
|
|
|
|
path('login_required/', login_required(views.PasswordResetView.as_view())),
|
|
|
|
path('login_required_login_url/', login_required(views.PasswordResetView.as_view(), login_url='/somewhere/')),
|
|
|
|
|
|
|
|
path('auth_processor_no_attr_access/', auth_processor_no_attr_access),
|
|
|
|
path('auth_processor_attr_access/', auth_processor_attr_access),
|
|
|
|
path('auth_processor_user/', auth_processor_user),
|
|
|
|
path('auth_processor_perms/', auth_processor_perms),
|
|
|
|
path('auth_processor_perm_in_perms/', auth_processor_perm_in_perms),
|
|
|
|
path('auth_processor_messages/', auth_processor_messages),
|
|
|
|
path(
|
|
|
|
'custom_request_auth_login/',
|
2016-05-15 15:28:00 +00:00
|
|
|
views.LoginView.as_view(authentication_form=CustomRequestAuthenticationForm)),
|
2018-12-07 22:52:28 +00:00
|
|
|
re_path('^userpage/(.+)/$', userpage, name='userpage'),
|
|
|
|
path('login/redirect_authenticated_user_default/', views.LoginView.as_view()),
|
|
|
|
path('login/redirect_authenticated_user/',
|
|
|
|
views.LoginView.as_view(redirect_authenticated_user=True)),
|
|
|
|
path('login/allowed_hosts/',
|
|
|
|
views.LoginView.as_view(success_url_allowed_hosts={'otherserver'})),
|
2014-01-14 15:43:27 +00:00
|
|
|
|
2018-03-12 15:48:46 +00:00
|
|
|
path('permission_required_redirect/', permission_required_redirect),
|
|
|
|
path('permission_required_exception/', permission_required_exception),
|
|
|
|
path('login_and_permission_required_exception/', login_and_permission_required_exception),
|
|
|
|
|
2016-08-14 20:42:49 +00:00
|
|
|
path('setlang/', set_language, name='set_language'),
|
2014-01-14 15:43:27 +00:00
|
|
|
# This line is only required to render the password reset with is_admin=True
|
2018-12-07 22:52:28 +00:00
|
|
|
path('admin/', admin.site.urls),
|
2014-04-02 00:46:34 +00:00
|
|
|
]
|