from django import forms
-from django.contrib.auth.models import User as DjangoUser
-from django.utils.translation import ugettext_lazy as _
+from django.contrib.auth.models import User
+from django.utils.translation import gettext_lazy as _
+
class UserBasicForm(forms.ModelForm):
class Meta:
- model = DjangoUser
+ model = User
fields = ('first_name', 'last_name', 'email',)
-class UserPasswordForm(forms.Form):
-
- new_password = forms.CharField(widget=forms.PasswordInput(),
- label=_("Your new password"))
- verifier = forms.CharField(widget=forms.PasswordInput(),
- label=_("Repeated password"))
-
- def clean(self):
- if 'verifier' not in self.cleaned_data or 'new_password' not in self.cleaned_data:
- return self.cleaned_data
+class OnboardingForm(forms.Form):
+ first_name = forms.CharField(label=_("First name"), max_length=150)
+ last_name = forms.CharField(label=_("Last name"), max_length=150)
+ email = forms.EmailField(label=_("External email"))
+ username = forms.CharField(
+ label=_("Username"),
+ max_length=150,
+ help_text=_("Auto-generated from first and last name")
+ )
- if self.cleaned_data['verifier'] != self.cleaned_data['new_password']:
- raise forms.ValidationError(_("Passwords do not match!"))
+ def clean_username(self):
+ username = self.cleaned_data['username']
+ if User.objects.filter(username=username).exists():
+ raise forms.ValidationError(_("User with this username already exists."))
+ return username
- return self.cleaned_data