Skip to content

Commit

Permalink
refactor(account/forms): Move all errors to adapter.error_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Dec 16, 2023
1 parent fbb104a commit 481928b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion allauth/account/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class DefaultAccountAdapter(object):
"Too many failed login attempts. Try again later."
),
"email_taken": _("A user is already registered with this email address."),
"enter_current_password": _("Please type your current password."),
"incorrect_password": _("Incorrect password."),
"password_min_length": _("Password must be a minimum of {0} characters."),
"unknown_email": _("The email address is not assigned to any user account"),
}

def __init__(self, request=None):
Expand Down Expand Up @@ -353,7 +356,7 @@ def clean_password(self, password, user=None):
min_length = app_settings.PASSWORD_MIN_LENGTH
if min_length and len(password) < min_length:
raise forms.ValidationError(
_("Password must be a minimum of {0} characters.").format(min_length)
self.error_message["password_min_length"].format(min_length)
)
validate_password(password, user)
return password
Expand Down
8 changes: 4 additions & 4 deletions allauth/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,9 @@ def __init__(self, *args, **kwargs):

def clean_oldpassword(self):
if not self.user.check_password(self.cleaned_data.get("oldpassword")):
raise forms.ValidationError(_("Please type your current password."))
raise forms.ValidationError(
get_adapter().error_messages["enter_current_password"]
)
return self.cleaned_data["oldpassword"]

def save(self):
Expand Down Expand Up @@ -580,9 +582,7 @@ def clean_email(self):
email = get_adapter().clean_email(email)
self.users = filter_users_by_email(email, is_active=True, prefer_verified=True)
if not self.users and not app_settings.PREVENT_ENUMERATION:
raise forms.ValidationError(
_("The email address is not assigned to any user account")
)
raise forms.ValidationError(get_adapter().error_messages["unknown_email"])
return self.cleaned_data["email"]

def save(self, request, **kwargs):
Expand Down

0 comments on commit 481928b

Please sign in to comment.