X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/37e278e43ece42375352c07d9f04991ef58d992c..64899b00071ae58add7ae31e45b0d9e2dce7770e:/src/accounts/forms.py?ds=inline diff --git a/src/accounts/forms.py b/src/accounts/forms.py index 5dcb842..5a1b62e 100644 --- a/src/accounts/forms.py +++ b/src/accounts/forms.py @@ -1,26 +1,28 @@ 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