51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
import re
|
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django import forms
|
|
from django.contrib.auth.forms import SetPasswordForm as OldSetPasswordForm, \
|
|
PasswordChangeForm as OldPasswordChangeForm
|
|
|
|
|
|
from authentic2.registration_backend.forms import RegistrationForm as AuthenticRegistrationForm
|
|
|
|
PASSWORD_RE = re.compile(r'^(?=.*[A-Z])(?=.*[!@#$&*])(?=.*[a-z]).{8,}$')
|
|
|
|
class RegistrationForm(AuthenticRegistrationForm):
|
|
# see http://dev.entrouvert.org/issues/3203
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(RegistrationForm, self).__init__(*args, **kwargs)
|
|
self.fields['password1'].help_text = _('At least 8 characters, '
|
|
'including one uppercase, one lowercase and a special '
|
|
'character')
|
|
|
|
def clean_password1(self):
|
|
global PASSWORD_RE
|
|
|
|
password = self.cleaned_data['password1']
|
|
if not PASSWORD_RE.match(password):
|
|
raise forms.ValidationError(_('invalid password'))
|
|
return password
|
|
|
|
class SetPasswordMixin(object):
|
|
def __init__(self, *args, **kwargs):
|
|
super(SetPasswordMixin, self).__init__(*args, **kwargs)
|
|
self.fields['new_password1'].help_text = _('At least 8 characters, '
|
|
'including one uppercase, one lowercase and a special '
|
|
'character')
|
|
|
|
def clean_new_password1(self):
|
|
global PASSWORD_RE
|
|
|
|
password = self.cleaned_data['new_password1']
|
|
if not PASSWORD_RE.match(password):
|
|
raise forms.ValidationError(_('invalid password'))
|
|
return password
|
|
|
|
class SetPasswordForm(SetPasswordMixin, OldSetPasswordForm):
|
|
pass
|
|
|
|
class PasswordChangeForm(SetPasswordMixin, OldPasswordChangeForm):
|
|
pass
|