From b438a2e72a4a646dda96d33329fec8ee118673bf Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Thu, 11 Sep 2014 01:45:47 +0200 Subject: [PATCH 2/3] urls not involved in registration process removed from registration backend --- authentic2/profile_urls.py | 29 +++++++++++++++++++++++++++ authentic2/registration_backend/urls.py | 34 +++----------------------------- authentic2/registration_backend/views.py | 19 ++++++++++-------- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/authentic2/profile_urls.py b/authentic2/profile_urls.py index 0e87426..1a4f63c 100644 --- a/authentic2/profile_urls.py +++ b/authentic2/profile_urls.py @@ -1,4 +1,13 @@ from django.conf.urls import patterns, url +from django.contrib.auth import views as auth_views + +from authentic2.utils import get_form_class +from . import app_settings + +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) urlpatterns = patterns('authentic2.views', url(r'^logged-in/$', 'logged_in', name='logged-in'), @@ -7,4 +16,24 @@ urlpatterns = patterns('authentic2.views', url(r'^change-email/verify/$', 'email_change_verify', name='email-change-verify'), url(r'^$', 'profile', name='account_management'), + url(r'^password/change/$', + auth_views.password_change, + {'password_change_form': CHANGE_PASSWORD_FORM_CLASS}, + name='auth_password_change'), + url(r'^password/change/done/$', + auth_views.password_change_done, + name='auth_password_change_done'), + url(r'^password/reset/confirm/(?P[0-9A-Za-z]+)-(?P.+)/$', + auth_views.password_reset_confirm, + {'set_password_form': SET_PASSWORD_FORM_CLASS}, + name='auth_password_reset_confirm'), + url(r'^password/reset/$', + auth_views.password_reset, + name='auth_password_reset'), + url(r'^password/reset/complete/$', + auth_views.password_reset_complete, + name='auth_password_reset_complete'), + url(r'^password/reset/done/$', + auth_views.password_reset_done, + name='auth_password_reset_done'), ) diff --git a/authentic2/registration_backend/urls.py b/authentic2/registration_backend/urls.py index 135143e..13b00ea 100644 --- a/authentic2/registration_backend/urls.py +++ b/authentic2/registration_backend/urls.py @@ -1,18 +1,10 @@ from django.conf.urls import patterns from django.conf.urls import url from django.utils.importlib import import_module -from django.contrib.auth import views as auth_views from django.views.generic.base import TemplateView +from django.contrib.auth.decorators import login_required -from authentic2.utils import get_form_class -from .. import app_settings -from .views import RegistrationView, ActivationView - -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) - +from .views import RegistrationView, ActivationView, DeleteView urlpatterns = patterns('authentic2.registration_backend.views', url(r'^activate/complete/$', @@ -34,27 +26,7 @@ urlpatterns = patterns('authentic2.registration_backend.views', url(r'^register/closed/$', TemplateView.as_view(template_name='registration/registration_closed.html'), name='registration_disallowed'), - url(r'^password/change/$', - auth_views.password_change, - {'password_change_form': CHANGE_PASSWORD_FORM_CLASS}, - name='auth_password_change'), - url(r'^password/change/done/$', - auth_views.password_change_done, - name='auth_password_change_done'), - url(r'^password/reset/confirm/(?P[0-9A-Za-z]+)-(?P.+)/$', - auth_views.password_reset_confirm, - {'set_password_form': SET_PASSWORD_FORM_CLASS}, - name='auth_password_reset_confirm'), url(r'^delete/$', - 'delete', + login_required(DeleteView.as_view()), name='delete_account'), - url(r'^password/reset/$', - auth_views.password_reset, - name='auth_password_reset'), - url(r'^password/reset/complete/$', - auth_views.password_reset_complete, - name='auth_password_reset_complete'), - url(r'^password/reset/done/$', - auth_views.password_reset_done, - name='auth_password_reset_done'), ) diff --git a/authentic2/registration_backend/views.py b/authentic2/registration_backend/views.py index 4b4ca8f..a6528a6 100644 --- a/authentic2/registration_backend/views.py +++ b/authentic2/registration_backend/views.py @@ -4,7 +4,6 @@ from datetime import datetime from django.shortcuts import redirect, render from django.utils.translation import ugettext as _ from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.contrib.sites.models import Site, RequestSite from django.contrib.auth.models import BaseUserManager, Group from django.conf import settings @@ -104,12 +103,17 @@ class ActivationView(TemplateView): new_user.groups = groups return new_user -@login_required -def delete(request, next_url='/'): - next_url = request.build_absolute_uri(request.META.get('HTTP_REFERER') or next_url) - if not app_settings.A2_REGISTRATION_CAN_DELETE_ACCOUNT: - return redirect(next_url) - if request.method == 'POST': +class DeleteView(TemplateView): + def get(self, request, *args, **kwargs): + next_url = request.build_absolute_uri(request.META.get('HTTP_REFERER')\ + or request.GET.get('next_url')) + if not app_settings.A2_REGISTRATION_CAN_DELETE_ACCOUNT: + return redirect(next_url) + return render(request, 'registration/delete_account.html') + + def post(self, request, *args, **kwargs): + next_url = request.build_absolute_uri(request.META.get('HTTP_REFERER')\ + or request.GET.get('next_url')) if 'submit' in request.POST: models.DeletedUser.objects.delete_user(request.user) logger.info(u'deletion of account %s requested' % request.user) @@ -117,4 +121,3 @@ def delete(request, next_url='/'): return redirect('auth_logout') else: return redirect(next_url) - return render(request, 'registration/delete_account.html') -- 2.1.0