1515
1616from ietf .person .models import Person , Email
1717from ietf .mailinglists .models import Whitelisted
18-
18+ from ietf . utils . text import isascii
1919
2020class RegistrationForm (forms .Form ):
2121 email = forms .EmailField (label = "Your email (lowercase)" )
@@ -32,9 +32,12 @@ def clean_email(self):
3232
3333
3434class PasswordForm (forms .Form ):
35- password = forms .CharField (widget = PasswordStrengthInput )
36- password_confirmation = forms .CharField (widget = PasswordConfirmationInput ,
37- help_text = "Enter the same password as above, for verification." )
35+ password = forms .CharField (widget = PasswordStrengthInput (attrs = {'class' :'password_strength' }))
36+ password_confirmation = forms .CharField (widget = PasswordConfirmationInput (
37+ confirm_with = 'password' ,
38+ attrs = {'class' :'password_confirmation' }),
39+ help_text = "Enter the same password as above, for verification." ,)
40+
3841
3942 def clean_password_confirmation (self ):
4043 password = self .cleaned_data .get ("password" , "" )
@@ -43,12 +46,6 @@ def clean_password_confirmation(self):
4346 raise forms .ValidationError ("The two password fields didn't match." )
4447 return password_confirmation
4548
46- class PersonPasswordForm (forms .ModelForm , PasswordForm ):
47- class Meta :
48- model = Person
49- fields = ['name' , 'ascii' ]
50-
51-
5249def ascii_cleaner (supposedly_ascii ):
5350 outside_printable_ascii_pattern = r'[^\x20-\x7F]'
5451 if re .search (outside_printable_ascii_pattern , supposedly_ascii ):
@@ -64,6 +61,26 @@ def prevent_system_name(name):
6461 if "(system)" in name_without_spaces .lower ():
6562 raise forms .ValidationError ("Please pick another name - this name is reserved." )
6663
64+ class PersonPasswordForm (forms .ModelForm , PasswordForm ):
65+
66+ class Meta :
67+ model = Person
68+ fields = ['name' , 'ascii' ]
69+
70+ def clean_name (self ):
71+ name = self .cleaned_data .get ('name' , '' )
72+ prevent_at_symbol (name )
73+ prevent_system_name (name )
74+
75+ return name
76+
77+ def clean_ascii (self ):
78+ ascii = self .cleaned_data .get ('ascii' , '' )
79+ if not isascii (ascii ):
80+ raise forms .ValidationError ("Ascii name contains non-ASCII characters." )
81+
82+ return ascii
83+
6784def get_person_form (* args , ** kwargs ):
6885
6986 exclude_list = ['time' , 'user' , 'photo_thumb' , 'photo' , ]
@@ -179,7 +196,9 @@ class ChangePasswordForm(forms.Form):
179196 current_password = forms .CharField (widget = forms .PasswordInput )
180197
181198 new_password = forms .CharField (widget = PasswordStrengthInput (attrs = {'class' :'password_strength' }))
182- new_password_confirmation = forms .CharField (widget = PasswordConfirmationInput )
199+ new_password_confirmation = forms .CharField (widget = PasswordConfirmationInput (
200+ confirm_with = 'new_password' ,
201+ attrs = {'class' :'password_confirmation' }))
183202
184203 def __init__ (self , user , data = None ):
185204 self .user = user
0 commit comments