diff --git a/bookwyrm/forms/landing.py b/bookwyrm/forms/landing.py index 36c18dfb8..a31e8a7c4 100644 --- a/bookwyrm/forms/landing.py +++ b/bookwyrm/forms/landing.py @@ -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) diff --git a/bookwyrm/templates/landing/password_reset.html b/bookwyrm/templates/landing/password_reset.html index 8348efd4f..d56cba625 100644 --- a/bookwyrm/templates/landing/password_reset.html +++ b/bookwyrm/templates/landing/password_reset.html @@ -26,7 +26,8 @@ {% trans "Password:" %}