Commit 2d26e024a0de34b6a89e4705058353c40bde8d74
Committed by
Sergio Oliveira
1 parent
67615bd0
Exists in
master
and in
13 other branches
Adding confirm password
Adding confirm password
Showing
1 changed file
with
28 additions
and
1 deletions
Show diff stats
colab/accounts/forms.py
@@ -50,6 +50,10 @@ class UserForm(forms.ModelForm): | @@ -50,6 +50,10 @@ class UserForm(forms.ModelForm): | ||
50 | 50 | ||
51 | class UserCreationForm(UserForm): | 51 | class UserCreationForm(UserForm): |
52 | 52 | ||
53 | + class Meta: | ||
54 | + model = User | ||
55 | + fields = ('first_name', 'last_name', 'username') | ||
56 | + | ||
53 | def clean_username(self): | 57 | def clean_username(self): |
54 | username = self.cleaned_data['username'] | 58 | username = self.cleaned_data['username'] |
55 | username = username.strip() | 59 | username = username.strip() |
@@ -57,9 +61,32 @@ class UserCreationForm(UserForm): | @@ -57,9 +61,32 @@ class UserCreationForm(UserForm): | ||
57 | raise forms.ValidationError(_('This field cannot be blank.')) | 61 | raise forms.ValidationError(_('This field cannot be blank.')) |
58 | return username | 62 | return username |
59 | 63 | ||
64 | + | ||
65 | +class UserCreationFormNoBrowserId(UserCreationForm): | ||
66 | + | ||
67 | + password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput) | ||
68 | + password2 = forms.CharField(label=_("Confirm Password "), widget=forms.PasswordInput) | ||
69 | + | ||
60 | class Meta: | 70 | class Meta: |
61 | model = User | 71 | model = User |
62 | - fields = ('first_name', 'last_name', 'username') | 72 | + fields = ('first_name', 'last_name','email', 'username') |
73 | + | ||
74 | + def clean_password2(self): | ||
75 | + password1 = self.cleaned_data.get('password1') | ||
76 | + password2 = self.cleaned_data.get('password2') | ||
77 | + | ||
78 | + if password1 and password2 and password1 != password2: | ||
79 | + raise forms.ValidationError(_("The two password fields didn't match.")) | ||
80 | + return password2 | ||
81 | + | ||
82 | + def save(self, commit=True): | ||
83 | + """ | ||
84 | + Saves the new password. | ||
85 | + """ | ||
86 | + self.instance.set_password(self.cleaned_data["password1"]) | ||
87 | + if commit: | ||
88 | + self.instance.save() | ||
89 | + return self.instance | ||
63 | 90 | ||
64 | 91 | ||
65 | class UserUpdateForm(UserForm): | 92 | class UserUpdateForm(UserForm): |