2014-04-02 08:46:34 +08:00
|
|
|
from django.conf.urls import url, include
|
2014-01-14 23:43:27 +08:00
|
|
|
from django.contrib import admin
|
2011-05-31 23:19:19 +08:00
|
|
|
from django.contrib.auth import context_processors
|
2013-02-24 07:25:05 +08:00
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
2009-04-02 01:02:32 +08:00
|
|
|
from django.contrib.auth.urls import urlpatterns
|
2014-08-12 22:54:42 +08:00
|
|
|
from django.contrib.auth import views
|
2010-09-11 03:38:57 +08:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2011-05-31 23:19:19 +08:00
|
|
|
from django.contrib.messages.api import info
|
2013-02-24 07:25:05 +08:00
|
|
|
from django.http import HttpResponse, HttpRequest
|
2011-05-31 23:19:19 +08:00
|
|
|
from django.shortcuts import render_to_response
|
2009-05-04 15:05:44 +08:00
|
|
|
from django.template import Template, RequestContext
|
2011-03-17 16:07:40 +08:00
|
|
|
from django.views.decorators.cache import never_cache
|
2009-05-04 15:05:44 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2013-02-24 07:25:05 +08:00
|
|
|
class CustomRequestAuthenticationForm(AuthenticationForm):
|
|
|
|
def __init__(self, request, *args, **kwargs):
|
|
|
|
assert isinstance(request, HttpRequest)
|
|
|
|
super(CustomRequestAuthenticationForm, self).__init__(request, *args, **kwargs)
|
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-03-17 16:07:40 +08:00
|
|
|
@never_cache
|
2009-05-04 15:05:44 +08: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-02 01:02:32 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-04-02 16:44:47 +08:00
|
|
|
def auth_processor_no_attr_access(request):
|
2013-09-08 23:05:16 +08:00
|
|
|
render_to_response('context_processors/auth_attrs_no_access.html',
|
2011-04-02 16:44:47 +08:00
|
|
|
RequestContext(request, {}, processors=[context_processors.auth]))
|
|
|
|
# *After* rendering, we check whether the session was accessed
|
|
|
|
return render_to_response('context_processors/auth_attrs_test_access.html',
|
2013-10-25 01:30:03 +08:00
|
|
|
{'session_accessed': request.session.accessed})
|
2011-04-02 16:44:47 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-04-02 16:44:47 +08:00
|
|
|
def auth_processor_attr_access(request):
|
2013-09-08 23:05:16 +08:00
|
|
|
render_to_response('context_processors/auth_attrs_access.html',
|
2011-04-02 16:44:47 +08:00
|
|
|
RequestContext(request, {}, processors=[context_processors.auth]))
|
|
|
|
return render_to_response('context_processors/auth_attrs_test_access.html',
|
2013-10-25 01:30:03 +08:00
|
|
|
{'session_accessed': request.session.accessed})
|
2011-04-02 16:44:47 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-04-02 16:44:47 +08:00
|
|
|
def auth_processor_user(request):
|
|
|
|
return render_to_response('context_processors/auth_attrs_user.html',
|
|
|
|
RequestContext(request, {}, processors=[context_processors.auth]))
|
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-04-02 16:44:47 +08:00
|
|
|
def auth_processor_perms(request):
|
|
|
|
return render_to_response('context_processors/auth_attrs_perms.html',
|
|
|
|
RequestContext(request, {}, processors=[context_processors.auth]))
|
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2012-09-30 23:13:23 +08:00
|
|
|
def auth_processor_perm_in_perms(request):
|
|
|
|
return render_to_response('context_processors/auth_attrs_perm_in_perms.html',
|
|
|
|
RequestContext(request, {}, processors=[context_processors.auth]))
|
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-04-02 16:44:47 +08:00
|
|
|
def auth_processor_messages(request):
|
2011-05-31 23:19:19 +08:00
|
|
|
info(request, "Message 1")
|
2011-04-02 16:44:47 +08:00
|
|
|
return render_to_response('context_processors/auth_attrs_messages.html',
|
|
|
|
RequestContext(request, {}, processors=[context_processors.auth]))
|
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-04-02 16:44:47 +08:00
|
|
|
def userpage(request):
|
|
|
|
pass
|
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2013-02-24 07:25:05 +08:00
|
|
|
def custom_request_auth_login(request):
|
2014-08-12 22:54:42 +08:00
|
|
|
return views.login(request, authentication_form=CustomRequestAuthenticationForm)
|
2013-02-24 07:25:05 +08:00
|
|
|
|
2009-04-02 01:02:32 +08:00
|
|
|
# special urls for auth test cases
|
2014-04-02 08:46:34 +08:00
|
|
|
urlpatterns += [
|
2014-08-12 22:54:42 +08:00
|
|
|
url(r'^logout/custom_query/$', views.logout, dict(redirect_field_name='follow')),
|
|
|
|
url(r'^logout/next_page/$', views.logout, dict(next_page='/somewhere/')),
|
|
|
|
url(r'^logout/next_page/named/$', views.logout, dict(next_page='password_reset')),
|
2014-04-02 08:46:34 +08:00
|
|
|
url(r'^remote_user/$', remote_user_auth_view),
|
2014-08-12 22:54:42 +08:00
|
|
|
url(r'^password_reset_from_email/$', views.password_reset, dict(from_email='staffmember@example.com')),
|
|
|
|
url(r'^password_reset/custom_redirect/$', views.password_reset, dict(post_reset_redirect='/custom/')),
|
|
|
|
url(r'^password_reset/custom_redirect/named/$', views.password_reset, dict(post_reset_redirect='password_reset')),
|
2014-09-04 20:15:09 +08:00
|
|
|
url(r'^password_reset/html_email_template/$', views.password_reset,
|
|
|
|
dict(html_email_template_name='registration/html_password_reset_email.html')),
|
2014-04-02 08:46:34 +08:00
|
|
|
url(r'^reset/custom/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
|
2014-08-12 22:54:42 +08:00
|
|
|
views.password_reset_confirm,
|
2013-05-19 18:57:06 +08:00
|
|
|
dict(post_reset_redirect='/custom/')),
|
2014-04-02 08:46:34 +08:00
|
|
|
url(r'^reset/custom/named/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
|
2014-08-12 22:54:42 +08:00
|
|
|
views.password_reset_confirm,
|
2013-05-19 18:57:06 +08:00
|
|
|
dict(post_reset_redirect='password_reset')),
|
2014-08-12 22:54:42 +08:00
|
|
|
url(r'^password_change/custom/$', views.password_change, dict(post_change_redirect='/custom/')),
|
|
|
|
url(r'^password_change/custom/named/$', views.password_change, dict(post_change_redirect='password_reset')),
|
|
|
|
url(r'^admin_password_reset/$', views.password_reset, dict(is_admin_site=True)),
|
|
|
|
url(r'^login_required/$', login_required(views.password_reset)),
|
|
|
|
url(r'^login_required_login_url/$', login_required(views.password_reset, login_url='/somewhere/')),
|
2014-04-02 08:46:34 +08: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),
|
|
|
|
url(r'^custom_request_auth_login/$', custom_request_auth_login),
|
2011-04-02 16:44:47 +08:00
|
|
|
url(r'^userpage/(.+)/$', userpage, name="userpage"),
|
2014-01-14 23:43:27 +08:00
|
|
|
|
|
|
|
# This line is only required to render the password reset with is_admin=True
|
2014-04-02 08:46:34 +08:00
|
|
|
url(r'^admin/', include(admin.site.urls)),
|
|
|
|
]
|