Skip to content

Commit

Permalink
Ne demande pas de mot de passe aux utilisateurs qui n'en ont pas (#6420)
Browse files Browse the repository at this point in the history
(cherry picked from commit 60ad124)
  • Loading branch information
Situphen authored and philippemilink committed Dec 4, 2022
1 parent abe111d commit f429410
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions zds/member/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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(
_(
"""
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion zds/utils/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "":
Expand Down

0 comments on commit f429410

Please sign in to comment.