diff --git a/colab/accounts/forms.py b/colab/accounts/forms.py index 254d0e6..0b23316 100644 --- a/colab/accounts/forms.py +++ b/colab/accounts/forms.py @@ -50,6 +50,10 @@ class UserForm(forms.ModelForm): class UserCreationForm(UserForm): + class Meta: + model = User + fields = ('first_name', 'last_name', 'username') + def clean_username(self): username = self.cleaned_data['username'] username = username.strip() @@ -57,9 +61,32 @@ class UserCreationForm(UserForm): raise forms.ValidationError(_('This field cannot be blank.')) return username + +class UserCreationFormNoBrowserId(UserCreationForm): + + password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput) + password2 = forms.CharField(label=_("Confirm Password "), widget=forms.PasswordInput) + class Meta: model = User - fields = ('first_name', 'last_name', 'username') + fields = ('first_name', 'last_name','email', 'username') + + def clean_password2(self): + password1 = self.cleaned_data.get('password1') + password2 = self.cleaned_data.get('password2') + + if password1 and password2 and password1 != password2: + raise forms.ValidationError(_("The two password fields didn't match.")) + return password2 + + def save(self, commit=True): + """ + Saves the new password. + """ + self.instance.set_password(self.cleaned_data["password1"]) + if commit: + self.instance.save() + return self.instance class UserUpdateForm(UserForm): -- libgit2 0.21.2