Mercurial > public > sg101
comparison gpp/accounts/forms.py @ 565:6a265b5768ca
For bitbucket issue #5, rework the duplicate email checking in the registration
form logic. Added tests for registration.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 04 Mar 2012 13:20:40 -0600 |
parents | 9e7ae8462f3f |
children |
comparison
equal
deleted
inserted
replaced
564:e5d3552d4ad0 | 565:6a265b5768ca |
---|---|
56 super(RegisterForm, self).__init__(*args, **kwargs) | 56 super(RegisterForm, self).__init__(*args, **kwargs) |
57 | 57 |
58 def clean_username(self): | 58 def clean_username(self): |
59 username = self.cleaned_data['username'] | 59 username = self.cleaned_data['username'] |
60 try: | 60 try: |
61 User.objects.get(username = username) | 61 User.objects.get(username=username) |
62 except User.DoesNotExist: | 62 except User.DoesNotExist: |
63 try: | 63 try: |
64 PendingUser.objects.get(username = username) | 64 PendingUser.objects.get(username=username) |
65 except PendingUser.DoesNotExist: | 65 except PendingUser.DoesNotExist: |
66 try: | 66 try: |
67 IllegalUsername.objects.get(username = username) | 67 IllegalUsername.objects.get(username=username) |
68 except IllegalUsername.DoesNotExist: | 68 except IllegalUsername.DoesNotExist: |
69 return username | 69 return username |
70 self._validation_error("That username is not allowed.", username) | 70 self._validation_error("That username is not allowed.", username) |
71 self._validation_error("A pending user with that username already exists.", username) | 71 self._validation_error("A pending user with that username already exists.", username) |
72 self._validation_error("A user with that username already exists.", username) | 72 self._validation_error("A user with that username already exists.", username) |
73 | 73 |
74 def clean_email(self): | 74 def clean_email(self): |
75 email = self.cleaned_data['email'] | 75 email = self.cleaned_data['email'] |
76 try: | 76 |
77 User.objects.get(email = email) | 77 if User.objects.filter(email=email).count(): |
78 except User.DoesNotExist: | 78 self._validation_error("A user with that email address already exists.", email) |
79 try: | 79 elif PendingUser.objects.filter(email=email).count(): |
80 PendingUser.objects.get(email = email) | |
81 except PendingUser.DoesNotExist: | |
82 try: | |
83 IllegalEmail.objects.get(email = email) | |
84 except IllegalEmail.DoesNotExist: | |
85 return email | |
86 self._validation_error("That email address is not allowed.", email) | |
87 self._validation_error("A pending user with that email address already exists.", email) | 80 self._validation_error("A pending user with that email address already exists.", email) |
88 self._validation_error("A user with that email address already exists.", email) | 81 elif IllegalEmail.objects.filter(email=email).count(): |
82 self._validation_error("That email address is not allowed.", email) | |
83 | |
84 # email is ok | |
85 return email | |
89 | 86 |
90 def clean_password2(self): | 87 def clean_password2(self): |
91 password1 = self.cleaned_data.get("password1", "") | 88 password1 = self.cleaned_data.get("password1", "") |
92 password2 = self.cleaned_data["password2"] | 89 password2 = self.cleaned_data["password2"] |
93 if password1 != password2: | 90 if password1 != password2: |