Changeset 8214
- Timestamp:
- 08/05/08 11:36:20 (4 months ago)
- Files:
-
- django/trunk/django/contrib/auth/forms.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/auth/forms.py
r8207 r8214 17 17 password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput) 18 18 password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput) 19 19 20 20 class Meta: 21 21 model = User 22 22 fields = ("username",) 23 23 24 24 def clean_username(self): 25 25 username = self.cleaned_data["username"] … … 29 29 return username 30 30 raise forms.ValidationError(_("A user with that username already exists.")) 31 31 32 32 def clean_password2(self): 33 33 password1 = self.cleaned_data["password1"] … … 36 36 raise forms.ValidationError(_("The two password fields didn't match.")) 37 37 return password2 38 38 39 39 def save(self, commit=True): 40 40 user = super(UserCreationForm, self).save(commit=False) … … 51 51 username = forms.CharField(label=_("Username"), max_length=30) 52 52 password = forms.CharField(label=_("Password"), widget=forms.PasswordInput) 53 53 54 54 def __init__(self, request=None, *args, **kwargs): 55 55 """ … … 62 62 self.user_cache = None 63 63 super(AuthenticationForm, self).__init__(*args, **kwargs) 64 64 65 65 def clean(self): 66 66 username = self.cleaned_data.get('username') 67 67 password = self.cleaned_data.get('password') 68 68 69 69 if username and password: 70 70 self.user_cache = authenticate(username=username, password=password) … … 73 73 elif not self.user_cache.is_active: 74 74 raise forms.ValidationError(_("This account is inactive.")) 75 75 76 76 # TODO: determine whether this should move to its own method. 77 77 if self.request: 78 78 if not self.request.session.test_cookie_worked(): 79 79 raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.")) 80 80 81 81 return self.cleaned_data 82 82 83 83 def get_user_id(self): 84 84 if self.user_cache: 85 85 return self.user_cache.id 86 86 return None 87 87 88 88 def get_user(self): 89 89 return self.user_cache … … 91 91 class PasswordResetForm(forms.Form): 92 92 email = forms.EmailField(label=_("E-mail"), max_length=75) 93 93 94 94 def clean_email(self): 95 95 """ … … 152 152 self.user.save() 153 153 return self.user 154 154 155 155 class PasswordChangeForm(SetPasswordForm): 156 156 """ … … 159 159 """ 160 160 old_password = forms.CharField(label=_("Old password"), widget=forms.PasswordInput) 161 161 162 162 def clean_old_password(self): 163 163 """ … … 169 169 return old_password 170 170 PasswordChangeForm.base_fields.keyOrder = ['old_password', 'new_password1', 'new_password2'] 171 171 172 172 class AdminPasswordChangeForm(forms.Form): 173 173 """ … … 176 176 password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput) 177 177 password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput) 178 178 179 179 def __init__(self, user, *args, **kwargs): 180 180 self.user = user 181 181 super(AdminPasswordChangeForm, self).__init__(*args, **kwargs) 182 182 183 183 def clean_password2(self): 184 184 password1 = self.cleaned_data.get('password1') … … 188 188 raise forms.ValidationError(_("The two password fields didn't match.")) 189 189 return password2 190 190 191 191 def save(self, commit=True): 192 192 """
