mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-16 02:32:22 +01:00
Reset password functionality.
This commit is contained in:
@ -9,7 +9,7 @@ class AuthenticationForm(BaseAuthenticationForm):
|
||||
super(AuthenticationForm, self).__init__(request, *args, **kwargs)
|
||||
|
||||
def confirm_login_allowed(self, user):
|
||||
if user.activation_token is not None:
|
||||
if user.activation_token:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['inactive'],
|
||||
code='inactive',
|
||||
@ -68,7 +68,39 @@ class RegistrationForm(forms.ModelForm):
|
||||
|
||||
def save(self, commit=True):
|
||||
user = super(RegistrationForm, self).save(commit=False)
|
||||
user.set_password(self.cleaned_data["password1"])
|
||||
user.set_password(self.cleaned_data.get("password1"))
|
||||
if commit:
|
||||
user.save()
|
||||
return user
|
||||
|
||||
|
||||
class ResetPasswordForm(forms.Form):
|
||||
error_messages = {
|
||||
'password_mismatch': _("The two password fields didn't match."),
|
||||
}
|
||||
password1 = forms.CharField(
|
||||
label=_("Password"),
|
||||
strip=False,
|
||||
widget=forms.PasswordInput,
|
||||
)
|
||||
password2 = forms.CharField(
|
||||
label=_("Password confirmation"),
|
||||
widget=forms.PasswordInput,
|
||||
strip=False,
|
||||
help_text=_("Enter the same password as before, for verification."),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ResetPasswordForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean_password2(self):
|
||||
password1 = self.cleaned_data.get("password1")
|
||||
password2 = self.cleaned_data.get("password2")
|
||||
|
||||
if password1 and password2 and password1 != password2:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['password_mismatch'],
|
||||
code='password_mismatch',
|
||||
)
|
||||
password_validation.validate_password(self.cleaned_data.get('password2'))
|
||||
return password2
|
||||
|
||||
Reference in New Issue
Block a user