From 60ad124776e4cc068ade6ae32a17578d42580f0f Mon Sep 17 00:00:00 2001 From: Situphen Date: Thu, 1 Dec 2022 13:45:15 +0100 Subject: [PATCH] Ne demande pas de mot de passe aux utilisateurs qui n'en ont pas (#6420) --- zds/member/forms.py | 6 +++--- zds/utils/forms.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/zds/member/forms.py b/zds/member/forms.py index 603aa25d54..327b266e34 100644 --- a/zds/member/forms.py +++ b/zds/member/forms.py @@ -411,7 +411,7 @@ def __init__(self, user, *args, **kwargs): Field("username", value=user.username), Field("email", value=user.email), Field("options"), - Field("password"), + self.insert_password_required_field(), ButtonHolder( StrictButton(_("Enregistrer"), type="submit"), ), @@ -449,7 +449,7 @@ def __init__(self, user, *args, **kwargs): self.user = user self.helper.layout = Layout( - Field("password"), + self.insert_password_required_field(), HTML( _( """ @@ -491,7 +491,7 @@ def __init__(self, user, *args, **kwargs): self.user = user self.helper.layout = Layout( - Field("password"), + self.insert_password_required_field(), Field("password_new"), Field("password_confirm"), ButtonHolder( diff --git a/zds/utils/forms.py b/zds/utils/forms.py index 5c81d0a495..e86324403a 100644 --- a/zds/utils/forms.py +++ b/zds/utils/forms.py @@ -168,11 +168,17 @@ class PasswordRequiredForm(forms.Form): widget=forms.PasswordInput, ) + def insert_password_required_field(self): + if self.user.has_usable_password(): + return Field("password") + else: + del self.fields["password"] + def clean(self): cleaned_data = super().clean() password = cleaned_data.get("password") - if password and self.user: + if password and self.user and self.user.has_usable_password(): user_exist = authenticate(username=self.user.username, password=password) # Check if the user exist. if not user_exist and password != "":