Commit 4c87a11b29906e6f553a4c06ea61f8917d01b0f8
1 parent
4bf6bfcb
Exists in
master
and in
3 other branches
Adding password fields to edit user
Showing
1 changed file
with
5 additions
and
34 deletions
Show diff stats
users/forms.py
... | ... | @@ -34,34 +34,10 @@ class Validation(forms.ModelForm): |
34 | 34 | |
35 | 35 | return image |
36 | 36 | |
37 | - # def clean_new_password(self): | |
38 | - # password = self.cleaned_data.get('new_password') | |
39 | - | |
40 | - # if self.is_edit and len(password) == 0: | |
41 | - # return password | |
42 | - | |
43 | - # # At least MIN_LENGTH long | |
44 | - # if len(password) < self.MIN_PASS_LENGTH: | |
45 | - # self._errors['new_password'] = [_("The new password must contain at least % d characters." % self.MIN_PASS_LENGTH)] | |
46 | - | |
47 | - # return ValueError | |
48 | - | |
49 | - # # At least one letter and one non-letter | |
50 | - # first_isalpha = password[0].isalpha() | |
51 | - # if all(c.isalpha() == first_isalpha for c in password): | |
52 | - # self._errors['new_password'] = [_('The password must contain at least one letter and at least one digit or a punctuation character.')] | |
53 | - | |
54 | - # return ValueError | |
55 | - | |
56 | - # return password | |
57 | - | |
58 | 37 | def clean_password2(self): |
59 | 38 | password = self.cleaned_data.get("new_password") |
60 | 39 | password2 = self.cleaned_data.get("password2") |
61 | - | |
62 | - #if self.is_edit and len(password) == 0: | |
63 | - # return password2 | |
64 | - | |
40 | + | |
65 | 41 | if password and password2 and password != password2: |
66 | 42 | self._errors['password2'] = [_('The confirmation password is incorrect.')] |
67 | 43 | |
... | ... | @@ -116,20 +92,15 @@ class UserForm(Validation): |
116 | 92 | super(UserForm, self).__init__(*args, **kwargs) |
117 | 93 | |
118 | 94 | self.is_edit = is_update |
119 | - | |
120 | - if self.is_edit: | |
121 | - del self.fields['new_password'] | |
122 | - del self.fields['password2'] | |
123 | 95 | |
124 | - if not is_edit: | |
125 | - new_password = forms.CharField(label=_('Password'), widget = forms.PasswordInput(render_value=True), required = False) | |
126 | - password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput(render_value=True), required = False) | |
96 | + new_password = forms.CharField(label = _('Password'), widget = forms.PasswordInput(render_value = True), required = False) | |
97 | + password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput(render_value = True), required = False) | |
127 | 98 | |
128 | 99 | |
129 | 100 | def save(self, commit=True): |
130 | 101 | super(UserForm, self).save(commit=False) |
131 | 102 | |
132 | - if not self.is_edit: | |
103 | + if not self.is_edit or self.cleaned_data['new_password'] != '': | |
133 | 104 | self.instance.set_password(self.cleaned_data['new_password']) |
134 | 105 | |
135 | 106 | self.instance.save() |
... | ... | @@ -138,7 +109,7 @@ class UserForm(Validation): |
138 | 109 | |
139 | 110 | class Meta: |
140 | 111 | model = User |
141 | - fields = ['email', 'username', 'last_name', 'social_name', 'description', 'show_email', 'image', 'is_staff', 'is_active'] | |
112 | + fields = ['email', 'username', 'last_name', 'social_name', 'description', 'show_email', 'image', 'is_staff', 'is_active',] | |
142 | 113 | widgets = { |
143 | 114 | 'description': forms.Textarea, |
144 | 115 | } | ... | ... |