Ejemplo n.º 1
0
class PasswordResetForm(auth_forms.PasswordResetForm):
    """Override PasswordResetForm from django.contrib.auth in order to allow
    any user alias when recovering a lost password
    """
    email = auth_forms.UsernameField(
        label=_("User name or email address"),
        widget=django.forms.TextInput(
            attrs={'placeholder': _('firstname.lastname.gradyear')}),
        max_length=254)

    def clean(self):
        cleaned_data = super(PasswordResetForm, self).clean()
        # Transform a login or an email alias to a main email address
        if 'email' not in cleaned_data:
            return cleaned_data
        email = cleaned_data['email']
        user = User.objects.get_for_login(email, True)
        if user is None:
            self._errors['email'] = self.error_class(
                [_("Unknown user account")])
            del cleaned_data['email']
            return cleaned_data

        cleaned_data['user'] = user
        cleaned_data['email'] = user.main_email
        return cleaned_data

    def get_users(self, email):
        # get_users is only called when self.cleaned_data has been populated,
        # otherwise there is an internal (Django) error
        assert self.cleaned_data["email"] == email
        assert self.cleaned_data['user'] is not None
        return [self.cleaned_data['user']]
Ejemplo n.º 2
0
class UserCreationForm(auth_forms.UserCreationForm):
    """Add fields to user create to support profile type."""

    username = auth_forms.UsernameField(
        required=False,
        strip=True,
        max_length=150,
        validators=[OptionalUnicodeUsernameValidator],
        help_text=USERNAME_HELP_TEXT)

    def clean_username(self):
        """Return the cleaned or auto-generated username."""

        username = self.cleaned_data.get("username")
        first_name = self.cleaned_data.get("first_name")
        last_name = self.cleaned_data.get("last_name")
        if not username:
            if not first_name or not last_name:
                raise forms.ValidationError(
                    "Username generation requires first and last name.")
            username_generator = rules.generate_username(first_name, last_name)
            username = next(username_generator)
            while models.User.objects.filter(username=username).exists():
                username = next(username_generator)
        return username

    class Meta:
        model = models.User
        fields = ("email", "first_name", "last_name")
Ejemplo n.º 3
0
class ModifiedRegistrationForm(reg_forms.RegistrationForm):
    username = auth_forms.UsernameField(widget=forms.TextInput(
        attrs={
            'placeholder': 'Логин',
            'class': 'input',
        }))
    email = forms.EmailField(widget=forms.EmailInput(
        attrs={
            'placeholder': 'Электронная почта',
            'class': 'input',
        }))
    password1 = forms.CharField(
        label='Пароль',
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'autocomplete': 'new-password',
                'placeholder': 'Пароль',
                'class': 'input',
            }),
        help_text=password_validation.password_validators_help_text_html(),
    )
    password2 = forms.CharField(
        label='Подтверждение пароля',
        widget=forms.PasswordInput(
            attrs={
                'autocomplete': 'new-password',
                'placeholder': 'Подтвердите пароль',
                'class': 'input',
            }),
        strip=False,
        help_text="Enter the same password as before, for verification.",
    )
Ejemplo n.º 4
0
class LoginForm(auth_forms.AuthenticationForm):
    """
    Form for logging in.
    """
    username = auth_forms.UsernameField(
        label='Email or Username',
        max_length=254,
        widget=forms.TextInput(
            attrs={
                'autofocus': True,
                'class': 'form-control',
                'placeholder': 'Email or Username'
            }),
    )
    password = forms.CharField(
        label='Password',
        strip=False,
        widget=forms.PasswordInput(attrs={
            'class': 'form-control',
            'placeholder': 'Password'
        }),
    )

    remember = forms.BooleanField(label='Remember Me', required=False)

    error_messages = {
        'invalid_login':
        ugettext_lazy(
            "Please enter a correct username/email and password. Note that the password "
            "field is case-sensitive."),
        'inactive':
        ugettext_lazy("This account has not been activated. Please check your "
                      "email for the activation link."),
    }
Ejemplo n.º 5
0
class AdminLoginForm(auth_form.AuthenticationForm):
    username = auth_form.UsernameField(
        max_length=254,
        widget=forms.TextInput(
            attrs={
                'autofocus': True,
                'type': 'text',
                'name': 'username',
                'id': 'user_name',
                'class': 'form-control',
                'placeholder': 'Enter User Name',
            }
        ),
    )
    password = forms.CharField(
        # label=_("Password"),
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'type': 'password',
                'name': 'password',
                'id': 'password',
                'class': 'form-control',
                'placeholder': 'Password',
            }
        ),
    )
Ejemplo n.º 6
0
class MyAuthenticationForm(f.AuthenticationForm):
    username = f.UsernameField(widget=forms.TextInput(
        attrs={'class': 'form-control form-control-user', 'autofocus': True, 'placeholder': _('Email')})
    )
    password = forms.CharField(
        label=_("Password"), strip=False,
        widget=forms.PasswordInput(attrs={'class': 'form-control form-control-user', 'placeholder': _('Password')}),
    )
Ejemplo n.º 7
0
class LoginForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(
        label='username', widget=forms.TextInput(attrs={'autofocus': True}))
    password = forms.CharField(
        label="Password",
        strip=False,
        widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}),
    )
Ejemplo n.º 8
0
class SignupForm(auth_forms.UserCreationForm):
    username = auth_forms.UsernameField(
        label=_("Username"),
        max_length=150,
        required=True,
        widget=forms.TextInput(
            attrs={
                'autofocus': True,
                'placeholder': 'Username',
                'class': 'form-control input-lg'
            }),
    )
    password1 = forms.CharField(
        label=_("Password"),
        strip=False,
        required=True,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Password',
            'class': 'form-control input-lg'
        }),
    )
    password2 = forms.CharField(
        label=_("Confirm password"),
        strip=False,
        required=True,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Confirm password',
            'class': 'form-control input-lg'
        }),
    )
    first_name = forms.CharField(
        label=_("First name"),
        max_length=30,
        required=False,
        widget=forms.TextInput(attrs={
            'placeholder': 'First name',
            'class': 'form-control input-lg'
        }))
    last_name = forms.CharField(
        label=_("Last name"),
        max_length=30,
        required=False,
        widget=forms.TextInput(attrs={
            'placeholder': 'Last name',
            'class': 'form-control input-lg'
        }))
    email = forms.EmailField(
        label=_("Email"),
        required=True,
        widget=forms.EmailInput(attrs={
            'placeholder': 'Email',
            'class': 'form-control input-lg'
        }))

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email', 'password1',
                  'password2')
Ejemplo n.º 9
0
class LoginForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(widget=forms.TextInput(
        attrs={
            'autofocus': True,
            'class': 'form-control'
        }))
    password = forms.CharField(
        strip=False,
        widget=forms.PasswordInput(attrs={'class': 'form-control'}))
Ejemplo n.º 10
0
class CustomLogIn(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(widget=forms.TextInput(
        attrs={
            "autofocus": True,
            "class": "form-control"
        }))
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=forms.PasswordInput(attrs={"class": "form-control"}),
    )
Ejemplo n.º 11
0
class CustomAuthenticationForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(
        label='Usuario',
        widget=forms.TextInput(attrs={'autofocus': True}),
    )
    password = forms.CharField(
        label="Contraseña",
        strip=False,
        widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}),
    )
    captcha = fields.ReCaptchaField()
Ejemplo n.º 12
0
class LoginForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(
        max_length=254,
        widget=forms.TextInput(attrs={'autofocus': '',
                                      'class': 'form-control'}),
    )
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=forms.PasswordInput(attrs={'class': 'form-control'}),
    )
Ejemplo n.º 13
0
class AuthLoginForm(forms.Form):
    """
	Base class for authenticating users. Extend this to get a form that accepts
	username/password logins.
	"""
    username = auth_forms.UsernameField(
        label=_("Username or email"),
        max_length=254,
        widget=forms.TextInput(attrs={'autofocus': True}),
    )
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=forms.PasswordInput,
    )

    error_messages = {
        'invalid_login':
        _("Please enter a correct username and password. Note that both fields may be case-sensitive."
          ),
    }

    def __init__(self, request=None, *args, **kwargs):
        self.request = request
        self.user = None
        super().__init__(*args, **kwargs)

    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')
        user = None

        if username is not None and password:
            if '@' in username:
                try:
                    user = ExternalIdentity.objects.get(email=username).user
                    username = None
                except ExternalIdentity.DoesNotExist:
                    pass

            self.user = authenticate(request=self.request,
                                     user=user,
                                     username=username,
                                     password=password)
            if self.user is None:
                raise forms.ValidationError(
                    self.error_messages['invalid_login'],
                    code='invalid_login',
                )

        return self.cleaned_data

    def process(self, request):
        auth_login(request, self.user)
Ejemplo n.º 14
0
class LoginForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(max_length=255,
        widget=forms.TextInput(attrs={"class": "form-control",
                                      "placeholder": "login"}))

    password = forms.CharField(max_length=255,
        widget=forms.PasswordInput(attrs={"class": "form-control",
                                          "placeholder": "password"}))

    class Meta:
        model = User
        fields = ['username', 'password']
Ejemplo n.º 15
0
class ConfirmUsernameForm(forms.ModelForm):
    confirm_username = authforms.UsernameField(widget=forms.TextInput(
        attrs={"autofocus": True}))

    class Meta:
        model = User
        fields = ("confirm_username", )

    def clean(self):
        cleaned_data = super().clean()
        confirm_username = cleaned_data.get("confirm_username")
        if confirm_username != self.instance.username:
            self.add_error("confirm_username", "Username does not match.")
Ejemplo n.º 16
0
class AuthenticationForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(
        max_length=254,
        widget=forms.TextInput(
            attrs={
                'autofocus': '',
                'placeholder': "Username (e.g. 'abcd1234') or email",
                'class': 'pure-u-1'
            }),
    )
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Password',
            'class': 'pure-u-1'
        }),
    )

    error_messages = auth_forms.AuthenticationForm.error_messages.copy()
    error_messages['inactive'] = _(
        'You need to activate your account before you can log in. Follow the instructions '
        'in the email you received, and then try again.')

    def clean(self):
        username = self.cleaned_data.get('username')
        try:
            str(uuid.UUID(username or ''))
        except ValueError:
            try:
                user = UserModel.objects.get(username=username)
            except UserModel.DoesNotExist:
                try:
                    user = UserModel.objects.get(emails__email=username)
                except UserModel.DoesNotExist:
                    username = str(uuid.uuid4())
                else:
                    username = str(user.pk)
            else:
                try:
                    UserModel.objects.get(emails__email=username)
                except UserModel.DoesNotExist:
                    pass
                username = str(user.pk)
        self.cleaned_data['username'] = username
        return super().clean()

    def confirm_login_allowed(self, user):
        if not settings.TWO_FACTOR_ENABLED and default_device(user):
            raise TwoFactorDisabled(None)
        return super().confirm_login_allowed(user)
Ejemplo n.º 17
0
class LoginForm(fm.AuthenticationForm):
    username = fm.UsernameField(
        label='用户名',
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': '请输入3-20位用户名'
        }))
    password = forms.CharField(
        label='密码',
        strip=False,
        widget=forms.PasswordInput(attrs={
            'class': 'form-control',
            'placeholder': '请输入密码'
        }),
    )
Ejemplo n.º 18
0
class ModifiedAuthenticationForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(widget=forms.TextInput(
        attrs={
            'placeholder': 'Логин',
            'class': 'input',
        }))
    password = forms.CharField(
        label='Пароль',
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'autocomplete': 'current-password',
                'placeholder': 'Пароль',
                'class': 'input',
            }),
    )
Ejemplo n.º 19
0
class LoginForm(auth_forms.AuthenticationForm):
    is_login = forms.BooleanField(
        widget=forms.HiddenInput,
        initial=True,
    )
    username = auth_forms.UsernameField(widget=forms.TextInput(attrs={'autofocus': True, 'class': 'form-control'}))
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=PasswordWidget(attrs={'autocomplete': 'current-password', 'class': 'form-control'}),
    )

    def is_valid(self):
        valid = super().is_valid()
        add_bootstrap_validation(self)
        return valid
Ejemplo n.º 20
0
class EditUserForm(forms.ModelForm):
    first_name = forms.CharField(widget=forms.TextInput(
        attrs={
            'class': 'form-control',
        }))
    last_name = forms.CharField(widget=forms.TextInput(attrs={
        'class': 'form-control',
    }))
    username = auth_form.UsernameField(widget=forms.TextInput(
        attrs={
            'class': 'form-control',
        }))

    class Meta:
        model = User
        fields = ['first_name', 'last_name', 'username']
Ejemplo n.º 21
0
class SignupForm(auth_forms.UserCreationForm):
    class Meta:
        model = MyUser
        fields = ('username', 'email', 'password1', 'password2')

    username = auth_forms.UsernameField(
        label=_("Username"),
        strip=False,
        initial="123",
        widget=forms.HiddenInput(attrs={'class': 'form-control'}),
    )

    email = forms.EmailField(
        label=_("Email"),
        max_length=200,
        widget=forms.EmailInput(attrs={'class': 'form-control'}),
    )

    password1 = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=PasswordWidget(attrs={'class': 'form-control'}),
        help_text=password_validation.password_validators_help_text_html(),
    )

    password2 = forms.CharField(
        label=_("Password confirmation"),
        widget=PasswordWidget(attrs={'class': 'form-control'}),
        strip=False,
    )

    def clean(self):
        data = super().clean()
        if 'email' in data:
            data['username'] = data['email']
        return data

    def is_valid(self):
        response = self.data.get('g-recaptcha-response', None)

        if not validate_recaptcha(response):
            self.add_error(None, 'reCaptcha should be validate')
            return False

        valid = super(SignupForm, self).is_valid()
        add_bootstrap_validation(self)
        return valid
Ejemplo n.º 22
0
class UserChangeForm(forms.ModelForm):
    """
    Replicate the form shown when the user model supplied by Django is not
    replaced with our own by copying most of the code
    """

    username = auth_forms.UsernameField(
        help_text="This username is optional because authentication is "
                  "generalized to work with other attributes such as email "
                  "addresses and phone numbers.",
        required=False,
    )

    password = auth_forms.ReadOnlyPasswordHashField(
        help_text="Raw passwords are not stored, so there is no way to see "
                  "this user's password, but you can change the password "
                  "using <a href=\"../password/\">this form</a>.",
    )
    secret_answer = auth_forms.ReadOnlyPasswordHashField(
        help_text="Raw answers are not stored, so there is no way to see "
                  "this user's answer, but you can change the answer "
                  "using the shell.",
    )

    class Meta:
        """
        Meta class for UserChangeForm
        """

        model = User
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        return self.initial["password"]

    def clean_secret_answer(self):
        return self.initial["secret_answer"]
Ejemplo n.º 23
0
class SignUpForm(auth_form.UserCreationForm):
    first_name = forms.CharField(widget=forms.TextInput(
        attrs={
            'class': 'form-control',
        }))
    last_name = forms.CharField(widget=forms.TextInput(attrs={
        'class': 'form-control',
    }))
    username = auth_form.UsernameField(widget=forms.TextInput(
        attrs={
            'class': 'form-control',
        }))
    email = forms.EmailField(max_length=100,
                             widget=forms.EmailInput(attrs={
                                 'class': 'form-control',
                             }))
    password1 = forms.CharField(
        label='Password',
        widget=forms.PasswordInput(attrs={
            'class': 'form-control',
        }))
    password2 = forms.CharField(
        label='Confirm password',
        widget=forms.PasswordInput(attrs={
            'class': 'form-control',
        }))

    class Meta:
        model = User
        fields = [
            'first_name', 'last_name', 'username', 'email', 'password1',
            'password2'
        ]

    def clean_email(self):
        email = self.cleaned_data.get('email')
        username = self.cleaned_data.get('username')
        if email and User.objects \
            .filter(email=email) \
            .exclude(username=username) \
            .exists():
            raise forms.ValidationError('Email address must be unique.')
        return email
Ejemplo n.º 24
0
class AuthenticationForm(authforms.AuthenticationForm):
    """
    signin form
    - custom error messages and widget settings for user authentication form
    - password remains if it is wrong
    - form focuses on first field
    """
    username = authforms.UsernameField(
        max_length=254,
        widget=forms.TextInput(attrs={'autofocus': True}),
    )
    password = forms.CharField(
        label=("Password"),
        strip=False,
        widget=forms.PasswordInput(render_value=True),
    )
    error_messages = {
        'invalid_login': ("Please enter a correct %(username)s and password. "
                          "Note that both "
                          "fields may be case-sensitive."),
    }
Ejemplo n.º 25
0
class AuthenticationForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(
        label=_("Username"),
        max_length=150,
        required=True,
        widget=forms.TextInput(
            attrs={
                'autofocus': True,
                'placeholder': 'Username',
                'class': 'form-control input-lg'
            }),
    )
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        required=True,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Password',
            'class': 'form-control input-lg'
        }),
    )
Ejemplo n.º 26
0
class AuthenticationForm(auth_forms.AuthenticationForm):
    # override username label
    username = auth_forms.UsernameField(
        label=_("User name or email address"),
        widget=django.forms.TextInput(
            attrs={'placeholder': _('firstname.lastname.gradyear')}),
        max_length=254)
    expiry = django.forms.ChoiceField(choices=[
        ('now', _("When I close my browser")),
        ('5min', _("After 5 minutes of inactivity")), ('nerver', _("Never"))
    ],
                                      label=_("Expire my session"),
                                      widget=django.forms.RadioSelect,
                                      initial='5min')

    def clean(self):
        super(AuthenticationForm, self).clean()
        expiry = self.cleaned_data.get('expiry')
        if expiry == 'now':
            self.request.session.set_expiry(0)
        elif expiry == '5min':
            self.request.session.set_expiry(300)
        return self.cleaned_data
Ejemplo n.º 27
0
class UserCreationForm(auth_forms.UserCreationForm):
    """
    创建用户
    """
    username = auth_forms.UsernameField(label=_('Username'),
                                        max_length=32,
                                        widget=forms.TextInput(
                                            attrs={
                                                'id': 'user-create-input-name',
                                                'class': 'form-control',
                                                'autofocus': True,
                                                'required': True,
                                                'placeholder': _('Username')
                                            }),
                                        help_text=_('Enter your username.'))
    password1 = forms.CharField(label=_('Password'),
                                strip=False,
                                widget=forms.PasswordInput(
                                    attrs={
                                        'id': 'user-create-input-password1',
                                        'class': 'form-control',
                                        'maxlength': 32,
                                        'minlength': 8,
                                        'required': True,
                                        'placeholder': _('Password')
                                    }),
                                help_text=_('Enter your password.'))
    password2 = forms.CharField(
        label=_('Password confirm'),
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'id': 'user-create-input-password2',
                'class': 'form-control',
                'maxlength': 32,
                'minlength': 8,
                'required': True,
                'placeholder': _('Password confirm')
            }),
        help_text=_('Enter the same password as before, for verification.'))
    email = forms.EmailField(label=_('Email address'),
                             widget=forms.EmailInput(
                                 attrs={
                                     'id': 'user-create-input-email',
                                     'class': 'form-control',
                                     'max_length': 64,
                                     'min_length': 8,
                                     'required': True,
                                     'placeholder': _('Email')
                                 }),
                             help_text=_('Enter your email address.'))
    password_length = forms.IntegerField(widget=forms.HiddenInput(),
                                         max_value=32,
                                         min_value=8,
                                         required=False)

    class Meta:
        model = get_user_model()
        fields = ("username", )

    def clean_username(self):
        # Just an example of cleaning a specific filed attribute
        # cleaned_data = super(LoginForm, self).clean()
        username = self.cleaned_data['username']

        if not re.match('^\w+$', username):
            self.add_error(
                'username', 'Enter a valid username. This value may contain '
                'only letters, numbers, and _ characters.')
        return username
Ejemplo n.º 28
0
class AuthenticationForm(auth_forms.AuthenticationForm):
    """
    用户登录验证
    """
    def __init__(self, *args, **kwargs):
        super(AuthenticationForm, self).__init__(*args, **kwargs)

    error_css_class = 'error'
    required_css_class = 'required'

    # email = forms.EmailField(
    #     widget=forms.EmailInput(attrs={'class': 'validate'}),
    #     max_length=32,
    #     min_length=6
    # )
    username = auth_forms.UsernameField(
        label=_('Username'),
        max_length=32,
        widget=forms.TextInput(
            attrs={
                'class': 'form-control',
                'id': 'login-input-username',
                'placeholder': _('Username'),
                'required': True,
                'spellcheck': 'false',
                'autofocus': 'autofocus',
            }),
    )
    password = forms.CharField(
        label=_('Password'),
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'class': 'form-control',
                'id': 'login-input-password',
                'placeholder': _('Password'),
                'maxlength': 32,
                'minlength': 8,
                'required': True
            }),
    )
    password_length = forms.IntegerField(widget=forms.HiddenInput(),
                                         max_value=32,
                                         min_value=8,
                                         required=False)
    remember_me = forms.BooleanField(
        label=_('Remember me'),
        label_suffix='',  # remove ':'
        widget=forms.CheckboxInput(attrs={'id': 'remember_me'}),
        required=False,
    )

    def clean_username(self):
        # Just an example of cleaning a specific filed attribute
        # cleaned_data = super(LoginForm, self).clean()
        username = self.cleaned_data['username']
        for i in '!@#$%^&*':
            if i in username:
                raise forms.ValidationError
        return username

    def confirm_login_allowed(self, user):
        # allow inactive user to login
        pass
Ejemplo n.º 29
0
class FakeCASLoginForm(forms.Form):
    username = auth_forms.UsernameField()
Ejemplo n.º 30
0
class SignupForm(auth_forms.UserCreationForm):
    username = auth_forms.UsernameField(
        label=_("Username"),
        max_length=150,
        required=True,
        widget=forms.TextInput(
            attrs={
                'autofocus': True,
                'placeholder': 'Username',
                'class': 'form-control input-lg'
            }),
    )
    password1 = forms.CharField(
        label=_("Password"),
        strip=False,
        required=True,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Password',
            'class': 'form-control input-lg'
        }),
    )
    password2 = forms.CharField(
        label=_("Confirm password"),
        strip=False,
        required=True,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Confirm password',
            'class': 'form-control input-lg'
        }),
    )
    first_name = forms.CharField(
        label=_("First name"),
        max_length=30,
        required=False,
        widget=forms.TextInput(attrs={
            'placeholder': 'First name',
            'class': 'form-control input-lg'
        }))
    last_name = forms.CharField(
        label=_("Last name"),
        max_length=30,
        required=False,
        widget=forms.TextInput(attrs={
            'placeholder': 'Last name',
            'class': 'form-control input-lg'
        }))
    email = forms.EmailField(
        label=_("Email"),
        required=True,
        widget=forms.EmailInput(attrs={
            'placeholder': 'Email',
            'class': 'form-control input-lg'
        }))
    position = forms.ModelMultipleChoiceField(
        label=_("Choose one or more groups"),
        queryset=Group.objects.all().order_by('name'),
        widget=forms.Select(attrs={
            'class': 'form-control selectpicker',
            'multiple': True
        }))

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email', 'password1',
                  'password2', 'position')