2015-01-25 12:00:30 +01:00
|
|
|
"""
|
|
|
|
This module defines form classes that can be extended by other gnuviechadmin
|
|
|
|
apps' forms.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-01-25 12:00:30 +01:00
|
|
|
|
|
|
|
from django import forms
|
2023-02-18 22:46:48 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2015-01-25 12:00:30 +01:00
|
|
|
|
|
|
|
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
|
|
|
"""
|
|
|
|
Error message for non matching passwords.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordModelFormMixin(forms.Form):
|
|
|
|
"""
|
|
|
|
A form for entering a password in two password fields. The form checks
|
|
|
|
whether both fields contain the same string.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
|
2015-01-25 12:00:30 +01:00
|
|
|
password1 = forms.CharField(
|
2023-02-18 22:46:48 +01:00
|
|
|
label=_("Password"),
|
|
|
|
widget=forms.PasswordInput,
|
2015-01-25 12:00:30 +01:00
|
|
|
)
|
|
|
|
password2 = forms.CharField(
|
2023-02-18 22:46:48 +01:00
|
|
|
label=_("Password (again)"),
|
|
|
|
widget=forms.PasswordInput,
|
2015-01-25 12:00:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def clean_password2(self):
|
|
|
|
"""
|
|
|
|
Check that the two password entries match.
|
|
|
|
|
|
|
|
:return: the validated password
|
|
|
|
:rtype: str or None
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
password1 = self.cleaned_data.get("password1")
|
|
|
|
password2 = self.cleaned_data.get("password2")
|
2015-01-25 12:00:30 +01:00
|
|
|
if password1 and password2 and password1 != password2:
|
|
|
|
raise forms.ValidationError(PASSWORD_MISMATCH_ERROR)
|
|
|
|
return password2
|