From aac94afcd0a59fdf473ca7b7fdb876437458af5b Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 20 Feb 2021 15:44:44 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20le=20formulaire=20de=20mdp=20K-?= =?UTF-8?q?F=C3=AAt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/forms.py | 23 +++++++++++++++++----- kfet/templates/kfet/account_update.html | 26 ++++++++++++------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index 79f8bb73..019a8e41 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -90,21 +90,34 @@ class AccountPwdForm(forms.Form): label="Mot de passe K-Fêt", required=False, help_text="Le mot de passe doit contenir au moins huit caractères", - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}), + min_length=8, ) pwd2 = forms.CharField( - label="Confirmer le mot de passe", required=False, widget=forms.PasswordInput + label="Confirmer le mot de passe", + required=False, + widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}), ) + def __init__(self, *args, account=None, **kwargs): + super().__init__(*args, **kwargs) + self.account = account + def clean(self): pwd1 = self.cleaned_data.get("pwd1", "") pwd2 = self.cleaned_data.get("pwd2", "") - if len(pwd1) < 8: - raise ValidationError("Mot de passe trop court") if pwd1 != pwd2: - raise ValidationError("Les mots de passes sont différents") + self.add_error("pwd2", "Les mots de passe doivent être identiques !") super().clean() + def save(self, commit=True): + password = self.cleaned_data["pwd1"] + self.account.set_password(password) + if commit: + self.account.save() + + return self.account + class CofForm(forms.ModelForm): def clean_is_cof(self): diff --git a/kfet/templates/kfet/account_update.html b/kfet/templates/kfet/account_update.html index 36b3d75d..dcb55555 100644 --- a/kfet/templates/kfet/account_update.html +++ b/kfet/templates/kfet/account_update.html @@ -6,29 +6,29 @@ {% block title %} {% if account.user == request.user %} - Modification de mes informations +Modification de mes informations {% else %} - {{ account.trigramme }} - Édition +{{ account.trigramme }} - Édition {% endif %} {% endblock %} {% block header-title %} {% if account.user == request.user %} - Modification de mes informations +Modification de mes informations {% else %} - Édition du compte {{ account.trigramme }} +Édition du compte {{ account.trigramme }} {% endif %} {% endblock %} {% block footer %} {% if not account.is_team %} - {% include "kfet/base_footer.html" %} +{% include "kfet/base_footer.html" %} {% endif %} {% endblock %} {% block main %} -
+ {% csrf_token %} {% include 'kfet/form_snippet.html' with form=user_info_form %} {% include 'kfet/form_snippet.html' with form=account_form %} @@ -36,21 +36,21 @@ {% include 'kfet/form_snippet.html' with form=pwd_form %} {% include 'kfet/form_snippet.html' with form=negative_form %} {% if perms.kfet.is_team %} - {% include 'kfet/form_authentication_snippet.html' %} + {% include 'kfet/form_authentication_snippet.html' %} {% endif %} {% include 'kfet/form_submit_snippet.html' with value="Mettre à jour" %}
-{% endblock %} +{% endblock %} \ No newline at end of file