registration_backend: allow overriding of set and change password forms

This commit is contained in:
Benjamin Dauvergne 2013-07-31 17:06:21 +02:00
parent 035db3ba2c
commit 4b281d3c1d
3 changed files with 52 additions and 14 deletions

View File

@ -80,6 +80,10 @@ __settings = dict(
definition='Root urlconf for the /accounts endpoints'),
A2_REGISTRATION_FORM_CLASS = Setting(default='authentic2.registration_backend.forms.RegistrationForm',
definition='Default registration form'),
A2_REGISTRATION_SET_PASSWORD_FORM_CLASS = Setting(default='registration.auth_urls.SetPasswordForm',
definition='Default set password form'),
A2_REGISTRATION_CHANGE_PASSWORD_FORM_CLASS = Setting(default='registration.auth_urls.SetPasswordForm',
definition='Default change password form'),
A2_REGISTRATION_CAN_DELETE_ACCOUNT = Setting(default=True,
definition='Can user self delete their account and all their data')
)

View File

@ -1,42 +1,60 @@
from django.utils.importlib import import_module
from django.conf.urls import patterns, url, include
from django.views.generic import TemplateView
from registration.views import activate
from registration.views import register
from django.contrib.auth import views as auth_views
from .. import app_settings
def get_form_class(form_class):
module, form_class = form_class.rsplit('.', 1)
module = import_module(module)
return getattr(module, form_class)
SET_PASSWORD_FORM_CLASS = get_form_class(
app_settings.A2_REGISTRATION_SET_PASSWORD_FORM_CLASS)
CHANGE_PASSWORD_FORM_CLASS = get_form_class(
app_settings.A2_REGISTRATION_CHANGE_PASSWORD_FORM_CLASS)
if app_settings.A2_REGISTRATION_AUTHORIZED:
urlpatterns = patterns('authentic2.registration_backend.views',
url(r'^activate/complete/$',
TemplateView.as_view(template_name='registration/activation_complete.html'),
'activate_complete',
name='registration_activation_complete'),
# Activation keys get matched by \w+ instead of the more specific
# [a-fA-F0-9]{40} because a bad activation key should still get to the view;
# that way it can return a sensible "invalid key" message instead of a
# confusing 404.
url(r'^activate/(?P<activation_key>\w+)/$',
activate,
'activate',
{'backend': 'authentic2.registration_backend.RegistrationBackend'},
name='registration_activate'),
url(r'^register/$',
register,
'register',
{'backend': 'authentic2.registration_backend.RegistrationBackend'},
name='registration_register'),
url(r'^register/complete/$',
TemplateView.as_view(template_name='registration/registration_complete.html'),
'register_complete',
name='registration_complete'),
url(r'^register/closed/$',
TemplateView.as_view(template_name='registration/registration_closed.html'),
'register_closed',
name='registration_disallowed'),
url(r'^delete/', 'delete', name='delete_account'),
(r'', include('registration.auth_urls')),
url(r'^delete/', 'delete', name='delete_account'),
)
else:
urlpatterns = patterns('',
(r'', include('registration.auth_urls')),
urlpatterns = patterns('')
urlpatterns += patterns('authentic2.registration_backend.views',
url(r'^password/change/$',
'password_change',
{'password_change_form': CHANGE_PASSWORD_FORM_CLASS},
name='auth_password_change'),
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
'password_reset_confirm',
{'set_password_form': SET_PASSWORD_FORM_CLASS},
name='auth_password_reset_confirm'),
(r'', include('registration.auth_urls')),
)

View File

@ -5,6 +5,12 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
from django.contrib.auth.views import password_change, password_reset_confirm
from registration.views import activate
from registration.views import register
from .. import models
@ -14,6 +20,16 @@ from .. import app_settings
logger = logging.getLogger(__name__)
activate_complete = TemplateView.as_view(template_name='registration/activation_complete.html')
register_complete = TemplateView.as_view(template_name='registration/registration_complete.html')
register_closed = TemplateView.as_view(template_name='registration/registration_closed.html')
@login_required
def delete(request, next_url='/'):
next_url = request.build_absolute_uri(request.META.get('HTTP_REFERER') or next_url)