Cleaned up whitespace
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8214 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9b4ff7c1ad
commit
8e24b37610
|
@ -16,11 +16,11 @@ class UserCreationForm(forms.ModelForm):
|
||||||
error_message = _("This value must contain only letters, numbers and underscores."))
|
error_message = _("This value must contain only letters, numbers and underscores."))
|
||||||
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||||
password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput)
|
password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ("username",)
|
fields = ("username",)
|
||||||
|
|
||||||
def clean_username(self):
|
def clean_username(self):
|
||||||
username = self.cleaned_data["username"]
|
username = self.cleaned_data["username"]
|
||||||
try:
|
try:
|
||||||
|
@ -28,14 +28,14 @@ class UserCreationForm(forms.ModelForm):
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return username
|
return username
|
||||||
raise forms.ValidationError(_("A user with that username already exists."))
|
raise forms.ValidationError(_("A user with that username already exists."))
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
password1 = self.cleaned_data["password1"]
|
password1 = self.cleaned_data["password1"]
|
||||||
password2 = self.cleaned_data["password2"]
|
password2 = self.cleaned_data["password2"]
|
||||||
if password1 != password2:
|
if password1 != password2:
|
||||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||||
return password2
|
return password2
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
user = super(UserCreationForm, self).save(commit=False)
|
user = super(UserCreationForm, self).save(commit=False)
|
||||||
user.set_password(self.cleaned_data["password1"])
|
user.set_password(self.cleaned_data["password1"])
|
||||||
|
@ -50,7 +50,7 @@ class AuthenticationForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
username = forms.CharField(label=_("Username"), max_length=30)
|
username = forms.CharField(label=_("Username"), max_length=30)
|
||||||
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||||
|
|
||||||
def __init__(self, request=None, *args, **kwargs):
|
def __init__(self, request=None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
If request is passed in, the form will validate that cookies are
|
If request is passed in, the form will validate that cookies are
|
||||||
|
@ -61,36 +61,36 @@ class AuthenticationForm(forms.Form):
|
||||||
self.request = request
|
self.request = request
|
||||||
self.user_cache = None
|
self.user_cache = None
|
||||||
super(AuthenticationForm, self).__init__(*args, **kwargs)
|
super(AuthenticationForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
username = self.cleaned_data.get('username')
|
username = self.cleaned_data.get('username')
|
||||||
password = self.cleaned_data.get('password')
|
password = self.cleaned_data.get('password')
|
||||||
|
|
||||||
if username and password:
|
if username and password:
|
||||||
self.user_cache = authenticate(username=username, password=password)
|
self.user_cache = authenticate(username=username, password=password)
|
||||||
if self.user_cache is None:
|
if self.user_cache is None:
|
||||||
raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive."))
|
raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive."))
|
||||||
elif not self.user_cache.is_active:
|
elif not self.user_cache.is_active:
|
||||||
raise forms.ValidationError(_("This account is inactive."))
|
raise forms.ValidationError(_("This account is inactive."))
|
||||||
|
|
||||||
# TODO: determine whether this should move to its own method.
|
# TODO: determine whether this should move to its own method.
|
||||||
if self.request:
|
if self.request:
|
||||||
if not self.request.session.test_cookie_worked():
|
if not self.request.session.test_cookie_worked():
|
||||||
raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."))
|
raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."))
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
def get_user_id(self):
|
def get_user_id(self):
|
||||||
if self.user_cache:
|
if self.user_cache:
|
||||||
return self.user_cache.id
|
return self.user_cache.id
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_user(self):
|
def get_user(self):
|
||||||
return self.user_cache
|
return self.user_cache
|
||||||
|
|
||||||
class PasswordResetForm(forms.Form):
|
class PasswordResetForm(forms.Form):
|
||||||
email = forms.EmailField(label=_("E-mail"), max_length=75)
|
email = forms.EmailField(label=_("E-mail"), max_length=75)
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
"""
|
"""
|
||||||
Validates that a user exists with the given e-mail address.
|
Validates that a user exists with the given e-mail address.
|
||||||
|
@ -151,14 +151,14 @@ class SetPasswordForm(forms.Form):
|
||||||
if commit:
|
if commit:
|
||||||
self.user.save()
|
self.user.save()
|
||||||
return self.user
|
return self.user
|
||||||
|
|
||||||
class PasswordChangeForm(SetPasswordForm):
|
class PasswordChangeForm(SetPasswordForm):
|
||||||
"""
|
"""
|
||||||
A form that lets a user change his/her password by entering
|
A form that lets a user change his/her password by entering
|
||||||
their old password.
|
their old password.
|
||||||
"""
|
"""
|
||||||
old_password = forms.CharField(label=_("Old password"), widget=forms.PasswordInput)
|
old_password = forms.CharField(label=_("Old password"), widget=forms.PasswordInput)
|
||||||
|
|
||||||
def clean_old_password(self):
|
def clean_old_password(self):
|
||||||
"""
|
"""
|
||||||
Validates that the old_password field is correct.
|
Validates that the old_password field is correct.
|
||||||
|
@ -168,18 +168,18 @@ class PasswordChangeForm(SetPasswordForm):
|
||||||
raise forms.ValidationError(_("Your old password was entered incorrectly. Please enter it again."))
|
raise forms.ValidationError(_("Your old password was entered incorrectly. Please enter it again."))
|
||||||
return old_password
|
return old_password
|
||||||
PasswordChangeForm.base_fields.keyOrder = ['old_password', 'new_password1', 'new_password2']
|
PasswordChangeForm.base_fields.keyOrder = ['old_password', 'new_password1', 'new_password2']
|
||||||
|
|
||||||
class AdminPasswordChangeForm(forms.Form):
|
class AdminPasswordChangeForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
A form used to change the password of a user in the admin interface.
|
A form used to change the password of a user in the admin interface.
|
||||||
"""
|
"""
|
||||||
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||||
password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput)
|
password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput)
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user, *args, **kwargs):
|
||||||
self.user = user
|
self.user = user
|
||||||
super(AdminPasswordChangeForm, self).__init__(*args, **kwargs)
|
super(AdminPasswordChangeForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
password1 = self.cleaned_data.get('password1')
|
password1 = self.cleaned_data.get('password1')
|
||||||
password2 = self.cleaned_data.get('password2')
|
password2 = self.cleaned_data.get('password2')
|
||||||
|
@ -187,7 +187,7 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
if password1 != password2:
|
if password1 != password2:
|
||||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||||
return password2
|
return password2
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
"""
|
"""
|
||||||
Saves the new password.
|
Saves the new password.
|
||||||
|
|
Loading…
Reference in New Issue