Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class C2CUserForm(forms.ModelForm):
- password = forms.CharField(label=_('password'), widget=forms.PasswordInput)
- password2 = forms.CharField(label=_('password confirmation'), widget=forms.PasswordInput)
- class Meta:
- model = User
- fields = ['first_name', 'last_name', 'email', 'password', 'password2']
- def clean_email(self):
- email = self.cleaned_data['email']
- try:
- user = User.objects.get(email=email)
- except User.DoesNotExist:
- return email
- raise forms.ValidationError(u'An account with %s as email already exists' % email)
- def clean(self):
- password = self.cleaned_data['password']
- password2 = self.cleaned_data['password2']
- if password != password2:
- raise forms.ValidationError(_('Both passwords mismatch'))
- return self.cleaned_data
- def save(self, *args, **kwargs):
- # username = email
- self.instance.username = self.instance.email
- # set password
- obj = super(C2CUserForm, self).save(*args, **kwargs)
- obj.set_password(self.cleaned_data['password'])
- obj.is_active= True
- obj.save()
- obj.groups.add(Group.objects.get(name=C2CUserProfile.ORGANISM))
- return obj
Add Comment
Please, Sign In to add comment