From 60646298b2566124205091c71e104c885b43ed44 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 2 Feb 2015 19:10:51 +0100 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mente=20les=20vues=20avec=20questions?= =?UTF-8?q?=20secr=C3=A8tes=20de=20login=20et=20r=C3=A9initialisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authentic2/src/authentic2_auf/__init__.py | 2 +- authentic2/src/authentic2_auf/urls.py | 9 +++-- authentic2/src/authentic2_auf/views.py | 47 ++++++++++++++++++----- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/authentic2/src/authentic2_auf/__init__.py b/authentic2/src/authentic2_auf/__init__.py index 3de27b7..5ef155d 100644 --- a/authentic2/src/authentic2_auf/__init__.py +++ b/authentic2/src/authentic2_auf/__init__.py @@ -9,7 +9,7 @@ class Plugin(object): return [] def get_apps(self): - return [__name__] + return [__name__, 'auf.django.secretquestions'] def get_before_middleware(self): return [] diff --git a/authentic2/src/authentic2_auf/urls.py b/authentic2/src/authentic2_auf/urls.py index d074665..975e3b1 100644 --- a/authentic2/src/authentic2_auf/urls.py +++ b/authentic2/src/authentic2_auf/urls.py @@ -3,14 +3,17 @@ from django.conf.urls import patterns, url from authentic2.decorators import setting_enabled, required from . import app_settings -from .views import lost_password_login, secret_questions +from .views import lost_password_login, secret_questions, lost_password_reset urlpatterns = required( setting_enabled('ENABLE', settings=app_settings), patterns('', - url('^accounts/auf/lost-password/$', lost_password_login, - name='authentic2-auf-lost-password'), + url('^accounts/auf/lost-password-login/$', lost_password_login, + name='authentic2-auf-lost-password-login'), url('^accounts/auf/secret-questions/$', secret_questions, name='authentic2-auf-secret-questions'), + # remplace la vue Django de recuperation + url('^accounts/password/reset/$', lost_password_reset, + name='auth_password_reset'), ) ) diff --git a/authentic2/src/authentic2_auf/views.py b/authentic2/src/authentic2_auf/views.py index fc5a192..6ab953e 100644 --- a/authentic2/src/authentic2_auf/views.py +++ b/authentic2/src/authentic2_auf/views.py @@ -1,16 +1,43 @@ -from django.shortcuts import render -from auth.django.secretquestions.decorators import secret_questions_required -from auth.django.secretquestions.views import secret_questions from django.contrib.auth import authenticate +from django.contrib.auth.forms import SetPasswordForm +from django.shortcuts import render +from django.contrib import messages +from django.utils.translation import ugettext as _ -from authentic2.utils import login -from . import decorators +from auf.django.secretquestions.decorators import secret_questions_required +from auf.django.secretquestions.views import setup_form -__ALL_ = [ 'sso' ] -@decorators.plugin_enabled +from authentic2.utils import login, continue_to_next_url +from authentic2.decorators import setting_enabled + + +from . import app_settings + +__ALL__ = [ 'lost_password_login', 'secret_questions' ] + +@setting_enabled('ENABLE', settings=app_settings) @secret_questions_required(60) -def lost_password_login(request) - user = authenticate(user=request.user) +def lost_password_login(request): + user = authenticate(user=request.secret_questions_user) return login(request, user, 'secret-questions') - + +@setting_enabled('ENABLE', settings=app_settings) +@secret_questions_required(6000) +def lost_password_reset(request): + user = authenticate(user=request.secret_questions_user) + if request.method == 'POST': + if 'cancel' in request.POST: + return continue_to_next_url(request, keep_params=False) + form = SetPasswordForm(data=request.POST, + user=user) + if form.is_valid(): + form.save() + messages.info(request, _('Your password has been reset, please login')) + return continue_to_next_url(request, keep_params=False) + else: + form = SetPasswordForm(user=user) + return render(request, 'authentic2_auf/reset_password.html', {'form': form}) + + +secret_questions = setup_form