comparison gpp/accounts/forms.py @ 155:ef93dc9f1992

Implement #44 - Add age confirmation to registration form. Also added a password > 6 rule.
author Brian Neal <bgneal@gmail.com>
date Sat, 19 Dec 2009 22:20:09 +0000
parents df56795771a6
children e3958aacd8dd
comparison
equal deleted inserted replaced
154:82deb8cc59e9 155:ef93dc9f1992
15 from accounts.models import IllegalEmail 15 from accounts.models import IllegalEmail
16 16
17 17
18 class RegisterForm(forms.Form): 18 class RegisterForm(forms.Form):
19 """Form used to register with the website""" 19 """Form used to register with the website"""
20 username = forms.RegexField(max_length = 30, regex = r'^\w+$', 20 username = forms.RegexField(max_length=30, regex = r'^\w+$',
21 error_messages = {'invalid' : 'Your username must be 30 characters or less and contain only letters, numbers and underscores.'}) 21 error_messages={
22 'invalid': 'Your username must be 30 characters or less and ' \
23 'contain only letters, numbers and underscores.'})
22 email = forms.EmailField() 24 email = forms.EmailField()
23 password1 = forms.CharField(label = "Password", widget = forms.PasswordInput) 25 password1 = forms.CharField(label = "Password", widget = forms.PasswordInput)
24 password2 = forms.CharField(label = "Password confirmation", widget = forms.PasswordInput) 26 password2 = forms.CharField(label = "Password confirmation", widget = forms.PasswordInput)
25 agree_tos = forms.BooleanField(required = True, label = 'I agree to the Terms of Service', 27 agree_age = forms.BooleanField(required=True,
26 error_messages = {'required' : 'You have not agreed to our Terms of Service'}) 28 label='I certify that I am over the age of 13',
27 agree_privacy = forms.BooleanField(required = True, label = 'I agree to the Privacy Policy', 29 error_messages={
28 error_messages = {'required' : 'You have not agreed to our Privacy Policy'}) 30 'required': 'Sorry, but you must be over the age of 13 to ' \
31 'register at our site.',
32 })
33 agree_tos = forms.BooleanField(required=True,
34 label='I agree to the Terms of Service',
35 error_messages={
36 'required': 'You have not agreed to our Terms of Service.',
37 })
38 agree_privacy = forms.BooleanField(required=True,
39 label='I agree to the Privacy Policy',
40 error_messages={
41 'required': 'You have not agreed to our Privacy Policy.',
42 })
29 43
30 def __init__(self, *args, **kwargs): 44 def __init__(self, *args, **kwargs):
31 self.ip = kwargs.pop('ip', '?') 45 self.ip = kwargs.pop('ip', '?')
32 super(RegisterForm, self).__init__(*args, **kwargs) 46 super(RegisterForm, self).__init__(*args, **kwargs)
33 47
66 def clean_password2(self): 80 def clean_password2(self):
67 password1 = self.cleaned_data.get("password1", "") 81 password1 = self.cleaned_data.get("password1", "")
68 password2 = self.cleaned_data["password2"] 82 password2 = self.cleaned_data["password2"]
69 if password1 != password2: 83 if password1 != password2:
70 self._validation_error("The two password fields didn't match.") 84 self._validation_error("The two password fields didn't match.")
85 if len(password1) < 6:
86 self._validation_error("Please choose a password of 6 characters or more.")
71 return password2 87 return password2
72 88
73 def save(self): 89 def save(self):
74 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'], 90 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'],
75 self.cleaned_data['email'], 91 self.cleaned_data['email'],