| 10 | |
| 11 | |
| 12 | class UserCreationForm(forms.ModelForm): |
| 13 | password1 = forms.CharField(label="Password", widget=forms.PasswordInput) |
| 14 | password2 = forms.CharField( |
| 15 | label="Password confirmation", widget=forms.PasswordInput |
| 16 | ) |
| 17 | |
| 18 | class Meta: |
| 19 | model = LessPassUser |
| 20 | fields = ("email",) |
| 21 | |
| 22 | def clean_password2(self): |
| 23 | password1 = self.cleaned_data.get("password1") |
| 24 | password2 = self.cleaned_data.get("password2") |
| 25 | if password1 and password2 and password1 != password2: |
| 26 | raise forms.ValidationError("Passwords don't match") |
| 27 | return password2 |
| 28 | |
| 29 | def save(self, commit=True): |
| 30 | user = super(UserCreationForm, self).save(commit=False) |
| 31 | user.set_password(self.cleaned_data["password1"]) |
| 32 | if commit: |
| 33 | user.save() |
| 34 | return user |
| 35 | |
| 36 | |
| 37 | class UserChangeForm(forms.ModelForm): |
nothing calls this directly
no outgoing calls
no test coverage detected