Пример #1
0
class PasswordResetForm(FlaskForm):
    username = StringField('username', validators=[DataRequired()])
    new_password = PasswordField('new_password', [
        validators.DataRequired(),
        validators.EqualTo('verify_new_password',
                           message='Passwords must match')
    ])
    verify_new_password = PasswordField('verify_new_password')
    token = StringField('token', validators=[DataRequired()])

    if RECAPTCHA is True:
        recaptcha = RecaptchaField('recaptcha')

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

    def validate(self):
        rv = FlaskForm.validate(self)
        if not rv:
            return False

        user = User.query.filter_by(username=self.username.data).first()
        if user is None:
            self.username.errors.append('Unknown username')
            return False

        self.user = user
        return True
Пример #2
0
class RegistrationForm(Form):
    username = TextField(u'Введите логин', [validators.Length(min=4, max=25)])
    password = PasswordField(u'Введите пароль', [
        validators.Required(),
        validators.EqualTo('confirm', message=u'Пароли должны совпадать')
    ])
    confirm = PasswordField(u'Повторите Ваш пароль еще раз')
Пример #3
0
class EditUser(Form):
    username = StringField('Username')
    email = StringField('Email', [validators.Email()])
    oldpassword = PasswordField('Old Password')
    password = PasswordField('New Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords must match')])
    confirm = PasswordField('Repeat Password')
Пример #4
0
class AddUser(Form):
    username = StringField('Username', [validators.DataRequired()])
    email = StringField('Email', [validators.DataRequired(), validators.Email()])
    password = PasswordField('New Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords must match')
    ])
    confirm = PasswordField('Repeat Password')
    adminuser = BooleanField('Admin?')
Пример #5
0
class RegisterForm(Form):
    """
    The register form.
    """
    username = TextField('Username', [validators.Required(), validators.Length(min=1, max=80), username_check])
    password = PasswordField('Password', [validators.Required()])
    password_repeat = PasswordField('Repeat password', [validators.EqualTo('password', message='Passwords must match.')])
    email = EmailField('Email', [validators.Required(), email_check])
    recaptcha = RecaptchaField()
Пример #6
0
class UserForm(Form):
    """
    The user form.
    """
    username = TextField(
        'Username', [validators.Required(),
                     validators.Length(min=1, max=80)])
    current_password = PasswordField('Current password',
                                     [validators.Optional()])
    new_password = PasswordField('New password', [validators.Optional()])
    new_password_repeat = PasswordField(
        'Repeat new password',
        [validators.EqualTo('new_password', message='Passwords must match.')])
    email = EmailField('Email', [validators.Required()])
    networks = FieldList(FormField(UserMemberForm))
    admin_flag = BooleanField('Has administrative privileges')
Пример #7
0
class RegistrationForm(Form):

    login = StringField(
        'Login', [validators.Length(min=4, max=25),
                  validators.DataRequired()])

    password = PasswordField('Password', [
        validators.DataRequired(),
        validators.EqualTo('verification', message='Passwords must match')
    ])

    full_name = StringField('Full name', [validators.DataRequired()])

    verification = PasswordField('Repeat password',
                                 [validators.DataRequired()])

    email = StringField('Email', [
        validators.Length(min=6, max=35),
        validators.Email(),
        validators.DataRequired()
    ])
Пример #8
0
class PasswordChangeForm(FlaskForm):
    current_password = PasswordField('current_password',
                                     validators=[DataRequired()])
    new_password = PasswordField('new_password', [
        validators.DataRequired(),
        validators.EqualTo('verify_new_password',
                           message='Passwords must match')
    ])

    verify_new_password = PasswordField('verify_new_password',
                                        validators=[DataRequired()])

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

    def validate(self):
        rv = FlaskForm.validate(self)
        if not rv:
            return False

        user = User.query.filter_by(username=current_user.username).first()

        if user is None:
            self.current_password.errors.append('Unknown user')
            return False
        print(self.current_password)
        print(self.new_password)
        if self.current_password.data == self.new_password:
            self.current_password.errors.append(
                'New password must be different then old one!')
            return False

        if not check_password_hash(user.password, self.current_password.data):
            self.current_password.errors.append('Invalid current password!')
            return False

        self.user = user
        return True