From f4cfc6f571addce47e4495af4e64d5d2ba7f6986 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 20 Jul 2016 12:06:33 +0200 Subject: [PATCH] =?UTF-8?q?Vue=20pour=20mot=20de=20passe=20oubli=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/registration/login.html | 8 +++----- users/forms.py | 4 ++++ users/models.py | 1 - users/urls.py | 1 + users/views.py | 22 ++++++++++++++++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/templates/registration/login.html b/templates/registration/login.html index 66b1644f..02f00ba1 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -19,14 +19,12 @@ {% endif %} {% endif %} -
+

{% csrf_token %} {% bootstrap_form form %} {% bootstrap_button "Login" button_type="submit" icon="log-in" %} -

- -{# Assumes you setup the password_reset view in your URLconf #} -{#

Lost password?

#} +

+

Mot de passe oublié ?

{% endblock %} diff --git a/users/forms.py b/users/forms.py index aa7cbf94..8fe0913f 100644 --- a/users/forms.py +++ b/users/forms.py @@ -70,3 +70,7 @@ class UserChangeForm(forms.ModelForm): if commit: user.save() return user + +class ResetPasswordForm(forms.Form): + pseudo = forms.CharField(label=u'Pseudo', max_length=255) + email = forms.EmailField(max_length=255) diff --git a/users/models.py b/users/models.py index db82dc1e..75eb72e7 100644 --- a/users/models.py +++ b/users/models.py @@ -322,7 +322,6 @@ class UserForm(InfoForm): class Meta(InfoForm.Meta): fields = '__all__' - class PasswordForm(ModelForm): class Meta: model = User diff --git a/users/urls.py b/users/urls.py index babdcb7e..863db9dc 100644 --- a/users/urls.py +++ b/users/urls.py @@ -22,6 +22,7 @@ urlpatterns = [ url(r'^index_school/$', views.index_school, name='index-school'), url(r'^mon_profil/$', views.mon_profil, name='mon-profil'), url(r'^process/(?P[a-z0-9]{32})/$', views.process, name='process'), + url(r'^reset_password/$', views.reset_password, name='reset-password'), url(r'^$', views.index, name='index'), ] diff --git a/users/views.py b/users/views.py index 7b245782..04637b75 100644 --- a/users/views.py +++ b/users/views.py @@ -17,7 +17,7 @@ from users.models import DelRightForm, BanForm, WhitelistForm, DelSchoolForm from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm from cotisations.models import Facture from machines.models import Machine, Interface -from users.forms import PassForm +from users.forms import PassForm, ResetPasswordForm from machines.views import unassign_ips, assign_ips from re2o.login import hashNT @@ -352,6 +352,23 @@ def profil(request, userid): } ) +def reset_password(request): + userform = ResetPasswordForm(request.POST or None) + if userform.is_valid(): + try: + user = User.objects.get(pseudo=userform.cleaned_data['pseudo'],email=userform.cleaned_data['email']) + except User.DoesNotExist: + messages.error(request, "Cet utilisateur n'existe pas") + return form({'userform': userform}, 'users/user.html', request) + req = Request() + req.type = Request.PASSWD + req.user = user + req.save() + reset_passwd_mail(req, request) + messages.success(request, "Un mail pour l'initialisation du mot de passe a été envoyé") + redirect("/") + return form({'userform': userform}, 'users/user.html', request) + def process(request, token): valid_reqs = Request.objects.filter(expires_at__gt=timezone.now()) req = get_object_or_404(valid_reqs, token=token) @@ -361,7 +378,8 @@ def process(request, token): elif req.type == Request.EMAIL: return process_email(request, req=req) else: - return error(request, 'Entrée incorrecte, contactez un admin') + messages.error(request, "Entrée incorrecte, contactez un admin") + redirect("/") def process_passwd(request, req): u_form = PassForm(request.POST or None)