2018-12-10 15:58:35 +00:00
|
|
|
"""passbook core user forms"""
|
|
|
|
|
|
|
|
from django import forms
|
2019-02-23 19:56:41 +00:00
|
|
|
from django.forms import ValidationError
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2018-12-10 15:58:35 +00:00
|
|
|
|
|
|
|
from passbook.core.models import User
|
|
|
|
|
|
|
|
|
|
|
|
class UserDetailForm(forms.ModelForm):
|
|
|
|
"""Update User Details"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = User
|
2019-02-27 14:09:05 +00:00
|
|
|
fields = ['username', 'name', 'email']
|
|
|
|
widgets = {
|
|
|
|
'name': forms.TextInput
|
|
|
|
}
|
2019-02-23 19:56:41 +00:00
|
|
|
|
|
|
|
class PasswordChangeForm(forms.Form):
|
|
|
|
"""Form to update password"""
|
|
|
|
|
|
|
|
password = forms.CharField(label=_('Password'),
|
2019-03-02 22:19:58 +00:00
|
|
|
widget=forms.PasswordInput(attrs={
|
|
|
|
'placeholder': _('New Password'),
|
|
|
|
'autocomplete': 'new-password'
|
|
|
|
}))
|
2019-02-23 19:56:41 +00:00
|
|
|
password_repeat = forms.CharField(label=_('Repeat Password'),
|
|
|
|
widget=forms.PasswordInput(attrs={
|
2019-03-02 22:19:58 +00:00
|
|
|
'placeholder': _('Repeat Password'),
|
|
|
|
'autocomplete': 'new-password'
|
2019-02-23 19:56:41 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
def clean_password_repeat(self):
|
|
|
|
"""Check if Password adheres to filter and if passwords matche"""
|
|
|
|
password = self.cleaned_data.get('password')
|
|
|
|
password_repeat = self.cleaned_data.get('password_repeat')
|
|
|
|
if password != password_repeat:
|
|
|
|
raise ValidationError(_("Passwords don't match"))
|
|
|
|
return self.cleaned_data.get('password_repeat')
|