Example #1
0
class ChangePasswordFormMixin(object):
    newPassword = PasswordField(
        'New Password', validators=[password_required, password_length])

    confirmNewPassword = PasswordField(
        'Confirm New Password',
        validators=[
            password_required,
            EqualTo('newPassword', message='RETYPE_PASSWORD_MISMATCH')
        ])
Example #2
0
class ExtendedRegisterForm(RegisterForm):
    name = StringField(
        '名字', validators=[name_required, name_length, unique_user_name])
    email = StringField(
        '邮箱', validators=[email_required, email_validator, unique_user_email])
    password = PasswordField('密码', validators=[password_required])
    password_confirm = PasswordField(
        '密码确认',
        validators=[
            EqualTo('password', message='RETYPE_PASSWORD_MISMATCH'),
            password_required
        ])
Example #3
0
class ExtendedRegisterForm(RegisterForm):
    name = StringField(
        "名字", validators=[name_required, name_length, unique_user_name])
    email = StringField(
        "邮箱", validators=[email_required, email_validator, unique_user_email])
    password = PasswordField("密码", validators=[password_required])
    password_confirm = PasswordField(
        "确认密码",
        validators=[
            EqualTo("password", message="RETYPE_PASSWORD_MISMATCH"),
            password_required,
        ],
    )
Example #4
0
class RegisterForm(ConfirmRegisterForm, NextFormMixin):
    password_confirm = PasswordField(
        get_form_field_label("retype_password"),
        validators=[
            EqualTo("password", message="RETYPE_PASSWORD_MISMATCH"),
            validators.Optional(),
        ],
    )

    csrf_token = uuid.uuid4()

    def validate(self):
        if not super(RegisterForm, self).validate():
            return False

        if not config_value("UNIFIED_SIGNIN"):
            # password_confirm required
            if not self.password_confirm.data or not self.password_confirm.data.strip(
            ):
                self.password_confirm.errors.append(
                    get_message("PASSWORD_NOT_PROVIDED")[0])
                return False

        return True

    def __init__(self, *args, **kwargs):
        super(RegisterForm, self).__init__(*args, **kwargs)
        if not self.next.data:
            self.next.data = request.args.get("next", "")
Example #5
0
class ExtendedLoginForm(LoginForm):

    email = StringField(_l('Email or Username'),
                        validators=[Required('Email required')])
    password = PasswordField(_l('Password'),
                             validators=[Required('Password required')])
    remember = BooleanField(_l('Remember Me'))
    submit = SubmitField(_l('Login'))
Example #6
0
    def scaffold_form(self):

        # Start with the standard form as provided by Flask-Admin. We've already told Flask-Admin to exclude the
        # password field from this form.
        form_class = super(UserAdmin, self).scaffold_form()

        # Add a password field, naming it "password2" and labeling it "New Password".
        form_class.password2 = PasswordField('New Password')
        return form_class
Example #7
0
class ResetEmailForOauthForm(SendConfirmationForm):
    origin_email = StringField('Current Email(ReadOnly',
                               render_kw={'readonly': True},
                               validators=[valid_user_email_for_oauth])
    email = StringField('New Email',
                        validators=[
                            email_required, email_validator, unique_user_email,
                            unique_email
                        ])
    password = PasswordField('Password(optional)')
Example #8
0
class ResetEmailForOauthForm(SendConfirmationForm):
    origin_email = StringField('当前邮箱(只读)',
                               render_kw={'readonly': True},
                               validators=[valid_user_email_fro_oauth])
    email = StringField('新邮箱',
                        validators=[
                            email_required, email_validator, unique_user_email,
                            unique_email
                        ])
    password = PasswordField('账户密码(可选)')
Example #9
0
class ExtendedConfirmRegisterForm(ConfirmRegisterForm):

    email = StringField(_l('Email address'),
                        validators=[Required('Email required')])
    agree = BooleanField(
        _l("I have read and agree the <a href='static/termsofuse.html'>Terms of use</a>"
           ))
    password = PasswordField(_l('Password'),
                             validators=[Required('Password required')])
    submit = SubmitField(_l('Register'))

    def validate_agree(self, field):
        if not field.data:
            raise ValidationError(
                _('Please indicate that you have read and agree to the Terms and Conditions'
                  ), 'error')
        else:
            return True

    def validate_email(self, field):
        allowed_email = UserAdmin.find_allowed_email(field.data)
        if allowed_email:
            if allowed_email.confirmed_at != None:
                raise ValidationError(
                    _('Email address has been confirmed earlier'))
            elif (allowed_email.creator
                  == 'system') and not allowed_email.approved:
                raise ValidationError(
                    _('Email address has not been approved yet'))
#            if (allowed_email.creator != 'system') or allowed_email.approved:
            else:
                return True
        raise ValidationError(_('Email address must be an authorized one'))

    def validate_username(self, field):
        user = shareds.user_datastore.get_user(field.data)
        if user:
            raise ValidationError(_('Username has been reserved already'))

    username = StringField(_l('Username'),
                           validators=[Required('Username required')])
    name = StringField(_l('Name'), validators=[Required('Name required')])
    language = SelectField(_l('Language'),
                           choices=shareds.app.config.get('LANGUAGES'),
                           validators=[Required(_('Language required'))])
Example #10
0
class ResetEmailForm(SendConfirmationForm):
    origin_email = StringField(
        'Current Email(ReadOnly)',
        render_kw={'readonly': True},
        validators=[email_required, email_validator, valid_user_email])
    email = StringField('New Email',
                        validators=[
                            email_required, email_validator, unique_user_email,
                            unique_email
                        ])
    password = PasswordField('Password', validators=[password_required])

    def validate(self):
        if not super(SendConfirmationForm, self).validate():
            return False
        if not verify_and_update_password(self.password.data, current_user):
            self.password.errors.append('Invalid password')
            return False
        return True
Example #11
0
 class MyChangePasswordForm(ChangePasswordForm):
     password = PasswordField("My Change Password Field")
Example #12
0
class ExtendedConfirmRegisterForm(ConfirmRegisterForm):
    username = StringField('Username', [Required()])
    first_name = StringField('First Name', [Required()])
    last_name = StringField('Last Name', [Required()])
    institution = StringField('Institution', [Required()])
    password_confirm = PasswordField()
Example #13
0
 class MyChangePasswordForm(ChangePasswordForm):
     password = PasswordField('My Change Password Field')
class ConfirmRegisterForm(Form, RegisterFormMixin):
    user_id = StringField(
        get_form_field_label("username"), validators=[],
    )

    username = StringField(
        get_form_field_label("username"), validators=[],
    )

    password = PasswordField(
        get_form_field_label("password"), validators=[validators.Optional()]
    )

    email = StringField(
        get_form_field_label("email"), validators=[validators.Optional()]
    )

    nickname = StringField(
        get_form_field_label("nickname"), validators=[validators.Optional()]
    )

    realname = StringField(
        get_form_field_label("realname"), validators=[validators.Optional()]
    )

    career = StringField(
        get_form_field_label("career"), validators=[validators.Optional()]
    )

    address = StringField(
        get_form_field_label("address"), validators=[validators.Optional()]
    )

    over18 = BooleanField(
        get_form_field_label("over18"), validators=[validators.Optional()]
    )

    jwt = StringField(
        get_form_field_label("jwt"), validators=[],
    )

    def validate(self):
        if not super(ConfirmRegisterForm, self).validate():
            return False

        # XXX hack with user_id data
        if not self.user_id.data and self.username.data:
            self.user_id.data = self.username.data

        # To support unified sign in - we permit registering with no password.
        if not config_value("UNIFIED_SIGNIN"):
            # password required
            if not self.password.data or not self.password.data.strip():
                self.password.errors.append(get_message("PASSWORD_NOT_PROVIDED")[0])
                return False

        if not self.password.data:
            return False

        if self.password.data:
            # We do explicit validation here for passwords
            # (rather than write a validator class) for 2 reasons:
            # 1) We want to control which fields are passed -
            #    sometimes that's current_user
            #    other times it's the registration fields.
            # 2) We want to be able to return multiple error messages.

            rfields = {}
            for k, v in self.data.items():
                if hasattr(_datastore.user_model, k):
                    rfields[k] = v
            if 'password' in rfields:
                del rfields["password"]

            pbad = _security._password_validator(self.password.data, True, **rfields)

            # validate with ptt-server

            user_id = self.user_id.data
            password = self.password.data
            ip = get_ip()

            email = self.email.data
            nickname = self.nickname.data
            realname = self.realname.data
            career = self.career.data
            address = self.address.data
            over18 = self.over18.data

            err, result = register_user(user_id, password, ip, email, nickname, realname, career, address, over18)
            if err is not None:
                self.user_id.errors = result['err']
                return False

            self.jwt.data = result

        return True
Example #15
0
class ExtendedLoginForm(LoginForm):
    email = StringField("邮箱/用户名", validators=[Required(message="未输入账号内容")])
    password = PasswordField("密码", validators=[password_required])
    def scaffold_form(self):
        form_class = super(UserAdmin, self).scaffold_form()
        form_class.password2 = PasswordField('New Password')

        return form_class
Example #17
0
class ExtendedLoginForm(LoginForm):
    email = StringField(
        'Email/Username',
        validators=[Required(message='No account info has been input.')])
    password = PasswordField('Password', validators=[password_required])
Example #18
0
class LocalizedLoginForm(LoginForm):
    email = StringField(label='Логин')
    password = PasswordField(label='Пароль')
    remember = BooleanField(label='Запомнить меня')
    submit = SubmitField(label='Войти')
Example #19
0
class ExtendedLoginForm(LoginForm):
    email = StringField('邮箱/用户名', validators=[Required(message='未输入账号内容')])
    password = PasswordField('密码', validators=[password_required])