Updates reset password flow to use validators
This commit is contained in:
parent
1bb0a9d998
commit
3846b201bd
3 changed files with 39 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
""" Forms for the landing pages """
|
||||
from django import forms
|
||||
from django.contrib.auth.password_validation import validate_password
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms import PasswordInput
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from bookwyrm import models
|
||||
|
@ -15,7 +15,7 @@ class LoginForm(CustomForm):
|
|||
fields = ["localname", "password"]
|
||||
help_texts = {f: None for f in fields}
|
||||
widgets = {
|
||||
"password": PasswordInput(),
|
||||
"password": forms.PasswordInput(),
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ class RegisterForm(CustomForm):
|
|||
model = models.User
|
||||
fields = ["localname", "email", "password"]
|
||||
help_texts = {f: None for f in fields}
|
||||
widgets = {"password": PasswordInput()}
|
||||
widgets = {"password": forms.PasswordInput()}
|
||||
|
||||
def clean(self):
|
||||
"""Check if the username is taken"""
|
||||
|
@ -49,3 +49,28 @@ class InviteRequestForm(CustomForm):
|
|||
class Meta:
|
||||
model = models.InviteRequest
|
||||
fields = ["email", "answer"]
|
||||
|
||||
|
||||
class PasswordResetForm(CustomForm):
|
||||
confirm_password = forms.CharField(widget=forms.PasswordInput)
|
||||
|
||||
class Meta:
|
||||
model = models.User
|
||||
fields = ["password"]
|
||||
widgets = {
|
||||
"password": forms.PasswordInput(),
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
"""Make sure the passwords match and are valid"""
|
||||
cleaned_data = super().clean()
|
||||
new_password = cleaned_data.get("password")
|
||||
confirm_password = self.data.get("confirm_password")
|
||||
|
||||
if new_password != confirm_password:
|
||||
self.add_error("confirm_password", _("Password does not match"))
|
||||
|
||||
try:
|
||||
validate_password(new_password)
|
||||
except ValidationError as err:
|
||||
self.add_error("password", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue