class UF(Form):
     email = wtforms_html5.EmailField('Email',
         default=user and user.email or None,
         validators=[
             validators.DataRequired(),
             validators.Email(),
             _validate_user_does_not_exist(
                 exclude=user and user.email or None)])
     password1 = wtforms.PasswordField('New password',
         validators = [
             not user and validators.Required() or validators.Optional(),
             validators.Length(min=10,
                 message=lazy_gettext('Password should be at least 10 characters long.'))])
     password2 = wtforms.PasswordField('Repeat password',
         validators = [
             validators.EqualTo('password1',
                 message=lazy_gettext("Passwords didn't match."))])
     # Note: by default, a new user is active
     active = wtforms.BooleanField('Active',default=not user or user.active,
         validators=(user and user.id==current_user.id and \
             [validate_checked(message=lazy_gettext("You can't deactivate yourself."))] or \
             []))
Beispiel #2
0
class RegistrationForm(Form):
    username = TextField("Username", [
        validators.Length(
            min=5,
            max=30,
            message="Incorrect length of the username: min=5 and max=30 chars")
    ])
    password = PasswordField("Password", [
        validators.Length(
            min=5,
            max=100,
            message="Incorrect length of the password: min=5 and max=100 chars"
        ),
        validators.EqualTo('confirm', message='Passwords must match')
    ])
    confirm = PasswordField("Repeat password", [
        validators.Length(
            min=5,
            max=100,
            message="Incorrect length of the password: min=5 and max=100 chars"
        )
    ])
Beispiel #3
0
class SignupForm(Form):
    first_name = StringField(
        'First Name *',
        [validators.Length(min=1, max=50),
         validators.DataRequired()])

    last_name = StringField(
        'Last Name *',
        [validators.Length(min=1, max=50),
         validators.DataRequired()])

    email_id = StringField(
        'Email *',
        [validators.Length(min=6, max=50),
         validators.DataRequired()])

    password = PasswordField('Password *', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message=' Passwords do not match')
    ])

    confirm = PasswordField('Confirm Password *', [validators.DataRequired()])

    usertype = SelectField('User Type',
                           choices=[('customer', 'Customer'), ('chef', 'Chef'),
                                    ('both', 'Customer + Chef')])

    # address information is optional
    apartment_no = StringField('Apartment No', [validators.Length(max=50)])
    street = StringField('Street', [validators.Length(max=50)])
    city = StringField('City', [validators.Length(max=50)])
    state = StringField('State', [validators.Length(max=10)])
    zipcode = StringField('Zipcode', [validators.Length(max=10)])

    # build list of countries for selection
    country = SelectField('Country', coerce=int)

    # optional
    phone_number = StringField('Phone', [validators.Length(max=50)])
Beispiel #4
0
class RegistrationForm(FlaskForm):
    email = EmailField(
        'email', validators=[validators.DataRequired(),
                             validators.Email()])

    password = PasswordField(
        'password',
        validators=[
            validators.DataRequired(),
            validators.Length(
                min=6, message="password must be greater than 6 characters")
        ])

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

    submit = SubmitField('submit', [validators.DataRequired()])
Beispiel #5
0
class RegistrationForm(Form):
    password = PasswordField('Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords must match'),
        validators.Length(min=8, max=32)
    ])
    confirm = PasswordField('Confirm Password')
    fname = StringField(
        'First Name',
        [validators.Length(min=2, max=32),
         validators.DataRequired()])
    lname = StringField(
        'Last Name',
        [validators.Length(min=2, max=32),
         validators.DataRequired()])
    email1 = StringField('Email', [
        validators.Length(min=5, max=48),
        validators.DataRequired(),
        validators.Email(
            message='Either email is invalid or already registered.')
    ])
    recaptcha = RecaptchaField(validators.DataRequired())
Beispiel #6
0
class RegisterForm(Form):
    name = StringField("Name/Last name:",
                       validators=[validators.Length(min=3, max=30)])
    username = StringField("Username:"******"Required")
                           ])
    email = StringField(
        "E-mail:",
        validators=[
            validators.Email(message="Please enter a valid e-mail address"),
            validators.DataRequired(message="Required")
        ])
    password = PasswordField(
        "Password:"******"confirm",
                               message="Your password does not match"),
            validators.DataRequired(message="Enter a stong password")
        ])
    confirm = PasswordField("Confirm password")
Beispiel #7
0
class RegisterForm(Form):
    username = StringField('Username', [
        validators.Required(message='Required field'),
        validators.length(min=4, max=45, message='Invalid length')
    ])
    email = EmailField('Email', [
        validators.Required(message='Required field'),
        validators.Email(message='Invalid Email'),
        validators.length(min=4, max=45, message='Invalid length')
    ])
    password = PasswordField('Password', [
        validators.Required(message='Required field'),
        validators.EqualTo('confirm', message='Passwords must match'),
        validators.length(max=66, message='Invalid length')
    ])
    confirm = PasswordField('Repeat password', [
        validators.Required(message='Required field'),
        validators.length(max=66, message='Invalid length')
    ])
    accept_tos = BooleanField('I accept the TOS',
                              [validators.Required(message='Required field')])
    honeypot = HiddenField('', [empty_field])
Beispiel #8
0
class RegistrationForm(FlaskForm):
    username = StringField(
        'Username',
        [validators.DataRequired(),
         validators.Length(min=3, max=50)],
        render_kw={"placeholder": "Fullname"})
    email = StringField('Email',
                        [validators.DataRequired(),
                         validators.Email()],
                        render_kw={"placeholder": "Email"})
    password = PasswordField(
        'Password',
        [validators.DataRequired(),
         validators.Length(min=8, max=30)],
        render_kw={"placeholder": "Password"})
    confirmpassword = PasswordField(
        'Confirm Password', [
            validators.DataRequired(),
            validators.EqualTo('password', 'Password must be equal')
        ],
        render_kw={"placeholder": "Confirm Password"})
    submit = SubmitField('Sign Up')
Beispiel #9
0
class EditUserForm(Form):
    sex = SelectField('Sex', coerce=str, choices=[("Mr", "Mr"), ("Ms", "Ms")])
    name = StringField(
        'Name', [validators.Length(min=1, max=50),
                 validators.DataRequired()])
    address = StringField(
        'Address',
        [validators.Length(min=1, max=100),
         validators.DataRequired()])
    dateofbirth = DateField('Date of birth', format='%Y-%m-%d')
    country = SelectField('Country',
                          coerce=str,
                          choices=[("US", "United States"),
                                   ("Aus", "Australia"), ('Ch', 'China')])
    phone = StringField('Phone', [validators.DataRequired()])
    email = StringField('Email', [validators.DataRequired()])
    password = PasswordField('Password', [
        validators.DataRequired(),
        validators.Length(min=6),
        validators.EqualTo('confirm', message='Passwords do not match')
    ])
    confirm = PasswordField('Re-Enter Password', [validators.DataRequired()])
Beispiel #10
0
class CustomerRegisterForm(FlaskForm):
    name = StringField('Name: ')
    username = StringField('Username: '******'Email: ', [validators.Email(), validators.DataRequired()])
    password = PasswordField('Password: '******'confirm', message=' Both password must match! ')])
    confirm = PasswordField('Repeat Password: '******'Country: ', [validators.DataRequired()])
    city = StringField('City: ', [validators.DataRequired()])
    contact = StringField('Contact: ', [validators.DataRequired()])
    address = StringField('Address: ', [validators.DataRequired()])
    zipcode = StringField('Zip code: ', [validators.DataRequired()])

    profile = FileField('Profile', validators=[FileAllowed(['jpg','png','jpeg','gif'], 'Image only please')])
    submit = SubmitField('Register')

    def validate_username(self, username):
        if Register.query.filter_by(username=username.data).first():
            raise ValidationError("This username is already in use!")
        
    def validate_email(self, email):
        if Register.query.filter_by(email=email.data).first():
            raise ValidationError("This email address is already in use!")
Beispiel #11
0
class UserProfileForm(UserRegisterForm):
    password = PasswordField('Password', [
        validators.Optional(),
        validators.Length(min=6, max=64),
        validators.EqualTo('confirm', message=pmm)
    ],
                             filters=[strip_filter])
    per_page = SelectField('Items per page',
                           coerce=int,
                           choices=[(n, n) for n in range(10, 21)])
    suggestion = SelectField('Show suggestions',
                             coerce=int,
                             choices=[(n, n) for n in range(5)])
    recently = SelectField('Recently added',
                           coerce=int,
                           choices=[(n, n) for n in range(5)])

    sort_type = SelectField('Sort type',
                            coerce=str,
                            choices=[('clicks', 'Clicks'),
                                     ('dateasc', 'Date asc'),
                                     ('datedesc', 'Date desc')])
Beispiel #12
0
class FormRegister(Form):
    """ 依照Model來建置相對應的Form  """
    username = StringField(
        '使用者名稱',
        validators=[validators.DataRequired(),
                    validators.Length(8, 30)])
    email = EmailField('Email',
                       validators=[
                           validators.DataRequired(),
                           validators.Length(1, 50),
                           validators.Email()
                       ])
    password = PasswordField('密碼',
                             validators=[
                                 validators.DataRequired(),
                                 validators.Length(5, 10),
                                 validators.EqualTo('password2',
                                                    message='密碼需要符合上欄輸入')
                             ])
    password2 = PasswordField('密碼(請重複一次)',
                              validators=[validators.DataRequired()])
    submit = SubmitField('建立帳號')
Beispiel #13
0
class RegistrationFull(Form):
    username = IntegerField('Employee ID')
    password = PasswordField('Password', [
        validators.Length(min=8, max=40),
        validators.EqualTo(
            'confirm', message="Passwords do not match!"), validators.InputRequired()
    ])
    confirm = PasswordField('Confirm Password', [validators.InputRequired()])
    email = EmailField('Email', [validators.InputRequired()])
    phone = StringField('Phone Number', [validators.InputRequired()])

    def validate_phone(form, field):
        if len(field.data) > 11:
            raise ValidationError('Invalid phone number.')
        try:
            input_number = phonenumbers.parse(field.data)
            if not (phonenumbers.is_valid_number(input_number)):
                raise ValidationError('Invalid phone number.')
        except:
            input_number = phonenumbers.parse("+1"+field.data)
            if not (phonenumbers.is_valid_number(input_number)):
                raise ValidationError('Invalid phone number.')
class RegisterForm(Form):
    """
    Registration Form
    """
    email = StringField(
        'Email',
        validators=[
            validators.DataRequired(),
            validators.Email(),
        ]
    )
    password = PasswordField(
        'Password',
        validators=[
            validators.DataRequired(),
            validators.Length(min=2),
            validators.EqualTo(
                'password2',
                message='Passwords must match'
            )
        ]
    )
    password2 = PasswordField(
        'Confirm password',
        validators=[validators.DataRequired()]
    )
    blog_title = StringField(
        'Give your learning journal a title',
        validators=[
            validators.DataRequired(),
        ]
    )
    blog_owner = StringField(
        'Name to use for the copyright statement',
        validators=[
            validators.DataRequired(),
        ]
    )
Beispiel #15
0
class RegisterForm(Form):
    username = simple.StringField(
        label='用户名',
        validators=[
            validators.DataRequired()
        ],
        widget=widgets.TextInput(),
        render_kw={'class': 'form-control', 'placeholder':'用户名'},
    )

    pwd = simple.PasswordField(
        label='密码',
        validators=[
            validators.DataRequired(message='密码不能为空.')
        ],
        widget=widgets.PasswordInput(),
        render_kw={'class': 'form-control', 'placeholder':'密码'}
    )

    pwd_confirm = simple.PasswordField(
        label='重复密码',
        validators=[
            validators.DataRequired(message='重复密码不能为空.'),
            validators.EqualTo('pwd', message="两次密码输入不一致")
        ],
        widget=widgets.PasswordInput(),
        render_kw={'class': 'form-control', 'placeholder':'确认密码'}
    )

    email = html5.EmailField(
        label='邮箱',
        validators=[
            validators.DataRequired(message='邮箱不能为空.'),
            validators.Email(message='邮箱格式错误')
        ],
        widget=widgets.TextInput(input_type='email'),
        render_kw={'class': 'form-control', 'placeholder':'邮箱'}
    )
Beispiel #16
0
class ChangePasswordForm(FlaskForm):
    """Change password form."""
    old_password = PasswordField(_('Old Password'), validators=[
        validators.DataRequired(_('Old Password is required')),
        ])
    new_password = PasswordField(_('New Password'), validators=[
        validators.DataRequired(_('New Password is required')),
        password_validator,
        ])
    retype_password = PasswordField(_('Retype New Password'), validators=[
        validators.EqualTo('new_password', message=_('New Password and Retype Password did not match'))
        ])
    submit = SubmitField(_('Change password'))

    def validate(self):
        # Use feature config to remove unused form fields
        user_manager =  current_app.user_manager
        if not user_manager.USER_REQUIRE_RETYPE_PASSWORD:
            delattr(self, 'retype_password')

        # # Add custom password validator if needed
        # has_been_added = False
        # for v in self.new_password.validators:
        #     if v==user_manager.password_validator:
        #         has_been_added = True
        # if not has_been_added:
        #     self.new_password.validators.append(user_manager.password_validator)

        # Validate field-validators
        if not super(ChangePasswordForm, self).validate(): return False

        # Verify current_user and current_password
        if not current_user or not user_manager.verify_password(self.old_password.data, current_user.password):
            self.old_password.errors.append(_('Old Password is incorrect'))
            return False

        # All is well
        return True
Beispiel #17
0
class RegisterForm(Form):
    name = StringField('姓名', [validators.Length(min=1, max=50)])
    username = StringField('用户名', [validators.Length(min=4, max=25)])
    email = StringField('邮箱', [validators.Length(min=6, max=50)])
    password = PasswordField('密码', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords do not match')
    ])
    confirm = PasswordField('确认密码')

    # User Register
    @app.route('/register', methods=['GET', 'POST'])
    def register():
        form = RegisterForm(request.form)
        if request.method == 'POST' and form.validate():
            name = form.name.data
            email = form.email.data
            username = form.username.data
            password = sha256_crypt.encrypt(str(form.password.data))

            # Create cursor
            cur = mysql.connection.cursor()

            # Execute query
            cur.execute(
                "INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)",
                (name, email, username, password))

            # Commit to DB
            mysql.connection.commit()

            # Close connection
            cur.close()

            flash('您已注册成功,现在可以登录啦', 'success')

            return redirect(url_for('login'))
        return render_template('register.html', form=form)
Beispiel #18
0
class RegisterForm(Form):

    name = StringField(
        "Full names",
        validators=[
            validators.Length(min=3, max=25),
            validators.DataRequired(message="Please Fill This Field")
        ])

    username = StringField(
        "Username",
        validators=[
            validators.Length(min=3, max=25),
            validators.DataRequired(message="Please Fill This Field")
        ])

    email = StringField(
        "Email",
        validators=[
            validators.Email(message="Please enter a valid email address"),
            validators.DataRequired(message="Please Fill This Field"),
        ])

    password = PasswordField(
        "Password",
        validators=[
            validators.Length(
                min=8,
                max=25,
                message="Password must be between 8 and 25 characters long"),
            validators.DataRequired(message="Please Fill This Field"),
            validators.EqualTo(fieldname="confirm",
                               message="Your Passwords Do Not Match")
        ])

    confirm = PasswordField(
        "Confirm Password",
        validators=[validators.DataRequired(message="Please Fill This Field")])
Beispiel #19
0
class RegisterForm(Form):
    username = StringField('Username',
                           [validators.length(min=4, max=50), codi_validator])
    email = EmailField('Email', [
        validators.length(min=6, max=100),
        validators.Required(message='El email es requerido'),
        validators.Email(message='Ingrese un email valido')
    ])
    password = PasswordField('Password', [
        validators.Required('El password es requerido.'),
        validators.EqualTo('confirm_password',
                           message='La contraseña no coinciden.')
    ])
    confirm_password = PasswordField('Confirm password')
    accept = BooleanField([validators.DataRequired()])
    honeypot = HiddenField("", [length_honeypot])

    # Validación por metodo para un campo.
    def validate_username(self, username):
        if User.get_by_username(username.data):
            raise validators.ValidationError('El username: '******', ya esta en uso.')

    # Validar si un correo ya existe en la base de datos.
    def validate_email(self, email):
        if User.get_by_email(email.data):
            raise validators.ValidationError('Este email ya existe.')

    # Sobre escribiendo el metodo validate para generar nuestras propias palidaciones
    def validate(self):
        if not Form.validate(self):
            return False

        if len(self.password.data) < 3:
            self.password.errors.append('El password es muy corto.')
            return False

        return True
Beispiel #20
0
class RegistrationForm(FlaskForm):

    firstname = StringField('First Name', [validators.Length(min=4, max=20)])
    lastname = StringField('Last Name', [validators.Length(min=4, max=20)])
    email = StringField('Email Address', [
        validators.Length(
            min=10,
            max=50,
            message="Email address must be 10 to 50 characters Long"),
        validators.Email()
    ])

    phonenumber = StringField(
        'Phone Number',
        [validators.Length(min=7, max=12),
         validators.Required()])

    password = PasswordField('Password', [
        validators.Length(
            min=8, max=25, message="Password must be 8 to 25 characters long"),
        validators.Required()
    ])

    confirm = PasswordField(
        'Repeat Password',
        [validators.EqualTo('password', message="Passwords must match. ")])

    submit = SubmitField('Register')

    def validate_email(self, email):
        user = User.query.filter_by(email=email.data).first()
        if user is not None:
            raise ValidationError("Email already in use. ")

    def validate_phone(self, phonenumber):
        user = User.query.filter_by(phonenumber=phonenumber.data).first()
        if user is not None:
            raise ValidationError("phone number  already in use. ")
Beispiel #21
0
class RegistrationForm(Form):	
	# Fields of the form.
	username = TextField('Username',
						 [username_existence_check,
						 validators.Length(
						 min=3, message=too_short_error_msg('Usernames', 3)),
						 validators.Length(
						 max=20, message=too_long_error_msg('Username', 20)),
						 validators.Regexp(
						 re.compile(r'^$|^[\w]+$'),
						 message=special_char_error_msg('Usernames'))])

	firstname = TextField('First name',
						  [validators.Length(
						  max=20, message=too_long_error_msg('Firstname', 20))])

	lastname = TextField('Last name',
						 [validators.Length(
						 max=20, message=too_long_error_msg('Lastname', 20))])

	password1 = PasswordField('New Password',
							 [validators.Length(
							 min=8, message=too_short_error_msg('Passwords', 8)),
							 validators.Regexp(
							 re.compile(r'\d.*([A-Z]|[a-z])|([A-Z]|[a-z]).*\d'),
							 message='Passwords must contain at least one letter and one number'),
							 validators.Regexp(
							 re.compile(r'^$|^[\w]+$'),
							 message=special_char_error_msg('Passwords'))])

	password2 = PasswordField('Repeat Password', 
							[validators.EqualTo('password1', message='Passwords do not match')])

	email = TextField('Email Address', 
					  [validators.Length(
					  max=255,
					  message=too_long_error_msg('Email', 255)),
					  email_check])
Beispiel #22
0
class ChangePasswordForm(Form):
    old_password = PasswordField(_('Old Password'), validators=[
        validators.DataRequired(_('Old Password is required')),
        ])
    new_password = PasswordField(_('New Password'), validators=[
        validators.DataRequired(_('New Password is required')),
        ])
    retype_password = PasswordField(_('Retype New Password'), validators=[
        validators.EqualTo('new_password', message=_('New Password and Retype Password did not match'))
        ])
    next = HiddenField()
    submit = SubmitField(_('Change Password'))

    def validate(self):
        # Use feature config to remove unused form fields
        user_manager =  current_app.user_manager
        if not user_manager.enable_retype_password:
            delattr(self, 'retype_password')

        # Add custom password validator if needed
        has_been_added = False
        for v in self.new_password.validators:
            if v==user_manager.password_validator:
                has_been_added = True
        if not has_been_added:
            self.new_password.validators.append(user_manager.password_validator)

        # Validate field-validators
        if not super(ChangePasswordForm, self).validate():
            return False

        # Verify current_user and current_password
        if not current_user or not user_manager.verify_password(self.old_password.data, current_user):
            self.old_password.errors.append(_('Old Password is incorrect'))
            return False

        # All is well
        return True
Beispiel #23
0
class SignupForm(Form):
    firstname = StringField("First name", [
        validators.length(
            min=1, max=MAX_COL_WIDTHS, message='First name too short/long.')
    ])
    surname = StringField("Surname", [
        validators.length(
            min=2, max=MAX_COL_WIDTHS, message='Surname too short/long.')
    ])
    email = StringField("Email", [
        validators.Email("Please enter a valid email address."),
        validators.length(max=MAX_COL_WIDTHS, message='email too long.')
    ])
    password = PasswordField('Password', [
        validators.length(
            min=MIN_PASS_LEN,
            message='{} characters needed in password.'.format(MIN_PASS_LEN)),
        validators.EqualTo('password2', message='Your passwords must match')
    ])
    password2 = PasswordField('Confirm Password', [validators.InputRequired()])

    # submit = SubmitField("Submit")

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)

    def validate(self):
        if not Form.validate(self):
            return False
        if Member.query.filter_by(email=self.email.data).first():
            self.email.errors.append("That email is already taken")
            return False
        if pc.get_entropy(self.password.data) == 'weak':
            # self.password.errors.append("That password is too simple")
            flash(f15)
            return True
        else:
            return True
Beispiel #24
0
class UpdatePasswordForm(FlaskForm):
    # assume that once we use this we know the user
    email = EmailField('Re-enter your email',
                       [validators.InputRequired(),
                        validators.Email()])
    password = PasswordField(
        'New Password',
        [validators.InputRequired(),
         validators.Length(min=8, max=20)])
    confirm = PasswordField(
        'Confirm Password',
        [validators.EqualTo('password', message='Passwords must match')])

    def validate_password(self, password):
        if not re.search("[A-Z]", password.data):
            password.errors.append(
                "Field must have at least one uppercase letter.")

        if not re.search("[a-z]", password.data):
            password.errors.append(
                "Field must have at least one lowercase letter.")

        if not re.search("[0-9]", password.data):
            password.errors.append("Field must have at least one number.")

        if not re.search("[!@#$&?]", password.data):
            password.errors.append("Field must have at least one symbol.")

    def verify_reset_token(self, token):
        print('verifying token')
        try:
            valid_email = jwt.decode(
                token,
                key=os.getenv('SECRET_KEY_FLASK'))['reset_password_email']
        except Exception as e:
            print(e)
            return None
        return User.query.filter_by(email=valid_email).first()
class StaffRegistrationForm(Form):
    first_name = StringField(
        'First Name',
        [validators.Length(min=2, max=20),
         validators.DataRequired()])
    last_name = StringField(
        'Last Name',
        [validators.Length(min=2, max=20),
         validators.DataRequired()])
    phone = StringField(
        'Phone Number',
        [validators.Length(min=10, max=10),
         validators.DataRequired()])
    email = StringField('Email Address', [
        validators.Length(min=6, max=50),
        validators.DataRequired(),
        validators.Email()
    ])
    a_line_one = StringField(
        'Line 1', [validators.Length(max=100),
                   validators.DataRequired()])
    a_line_two = StringField('Line 2', [validators.Length(max=100)])
    a_city = StringField(
        'City', [validators.Length(min=2, max=50),
                 validators.DataRequired()])
    a_state = SelectField('State', choices=state_list, coerce=str)
    a_zipcode = StringField(
        'Zip Code',
        [validators.Length(min=5, max=5),
         validators.DataRequired()])
    salary = IntegerField('Salary', [validators.DataRequired()])
    job_title = StringField(
        'Job Title',
        [validators.Length(min=1, max=20),
         validators.DataRequired()])
    confirm = StringField(
        'Repeat Email for Confirmation',
        [validators.EqualTo('email', message='Emails must match')])
Beispiel #26
0
class AddAuthForm(ExtendedForm):
    login = TextField(_('Username'), [validators.Required(), \
                         validators.Length(min=4, max=25)])
    password = PasswordField(_('Password'), [validators.Required(), \
                             validators.EqualTo('password2', \
                             message=_('Passwords must match'))])
    password2 = PasswordField(_('Repeat Password'), [validators.Required()])
    email = TextField(_('Email Address'), [validators.Required(), \
                      validators.Email()])

    def validate_login(form, field):
        if AuthUser.get_by_login(field.data) is not None:
            raise validators.ValidationError(
                _('Sorry that username already exists.'))

    def create_user(self, auth_id, login):
        id = DBSession.query(AuthID).filter(AuthID.id == auth_id).one()
        user = AuthUser(
            login=login,
            password=self.data['password'],
            email=self.data['email'],
        )
        id.users.append(user)
        DBSession.add(user)
        DBSession.flush()

        return user

    def save(self, auth_id):
        new_user = self.create_user(auth_id, self.data['login'])
        self.after_signup(user=new_user)

    def after_signup(self, **kwargs):
        """ Function to be overloaded and called after form submission
        to allow you the ability to save additional form data or perform
        extra actions after the form submission.
        """
        pass
Beispiel #27
0
class RegisterForm(ExtendedForm):
    """ Registration Form
    """
    login = TextField(_('Username'), [validators.Required(), \
                         validators.Length(min=4, max=25)])
    password = PasswordField(_('Password'), [validators.Required(), \
                             validators.EqualTo('password2', \
                             message=_('Passwords must match'))])
    password2 = PasswordField(_('Repeat Password'), [validators.Required()])
    email = TextField(_('Email Address'), [validators.Required(), \
                      validators.Email()])

    def validate_login(form, field):
        if AuthUser.get_by_login(field.data) is not None:
            raise validators.ValidationError(
                _('Sorry that username already exists.'))

    def create_user(self, login):
        group = self.request.registry.settings.get('apex.default_user_group',
                                                   None)
        user = apex.lib.libapex.create_user(username=login,
                                            password=self.data['password'],
                                            email=self.data['email'],
                                            group=group)
        return user

    def save(self):
        new_user = self.create_user(self.data['login'])
        self.after_signup(user=new_user)

        return new_user

    def after_signup(self, **kwargs):
        """ Function to be overloaded and called after form submission
        to allow you the ability to save additional form data or perform
        extra actions after the form submission.
        """
        pass
Beispiel #28
0
class ChangePasswordForm(FlaskForm):
    """Change password form."""
    old_password = PasswordField(_l('Old Password'),
                                 validators=[
                                     validators.DataRequired(
                                         _l('Old Password is required')),
                                 ])
    new_password = PasswordField(_l('New Password'),
                                 validators=[
                                     validators.DataRequired(
                                         _l('New Password is required')),
                                     password_validator,
                                 ])
    retype_password = PasswordField(
        _l('Retype New Password'),
        validators=[
            validators.EqualTo(
                'new_password',
                message=_l('New Password and Retype Password did not match'))
        ])
    submit = SubmitField(_l('Change password'))

    def validate(self):
        # Use feature config to remove unused form fields
        if not current_app.auth.AUTH_REQUIRE_RETYPE_PASSWORD:
            delattr(self, 'retype_password')

        # Validate field-validators
        if not super(ChangePasswordForm, self).validate(): return False

        # Verify current_user and current_password
        if not current_user or not current_app.auth.password_manager.verify_password(
                self.old_password.data, current_user.password):
            self.old_password.errors.append(_l('Old Password is incorrect'))
            return False

        # All is well
        return True
Beispiel #29
0
class FormRegister(Form):
    """依照Model來建置相對應的Form
    
    password2: 用來確認兩次的密碼輸入相同
    """
    def validate_email(self, field):
        if UserInfo.query.filter_by(email=field.data).first():
            raise validators.ValidationError(
                'Email already register by somebody')

    def validate_username(self, field):
        if UserInfo.query.filter_by(username=field.data).first():
            raise validators.ValidationError(
                'UserName already register by somebody')

    username = StringField(
        'UserName',
        validators=[
            validators.DataRequired(),
            # validators.Length(10, 30)
        ])
    email = EmailField(
        'Email',
        validators=[
            validators.DataRequired(),
            # validators.Length(1, 50),
            validators.Email()
        ])
    password = PasswordField(
        'Password',
        validators=[
            validators.DataRequired(),
            # validators.Length(5, 10),
            validators.EqualTo('password2', message='PASSWORD NEED MATCH')
        ])
    password2 = PasswordField('Confirm PassWord',
                              validators=[validators.DataRequired()])
    submit = SubmitField('Register New Account')
Beispiel #30
0
class ChangePasswordForm(BaseForm):
    username = StringField(
        label='用户名',
        validators=[
            DataRequired(),
            validators.Length(2, 15, message='昵称至少需要两个字符,最多15个字符')
        ],
        widget=widgets.TextInput(),
        render_kw={'class': 'form-control'},
        default='root'
    )

    old_password = simple.PasswordField(
        label='原有密码',
        validators=[
            DataRequired()],
        widget=widgets.PasswordInput(),
        render_kw={'class': 'form-control'}
    )
    new_password1 = simple.PasswordField(
        label='新密码',
        validators=[
            DataRequired(),
            validators.Length(6, 10, message='密码长度至少需要在6到20个字符之间'),
            validators.EqualTo('new_password2', message='两次输入的密码不一致')],
        render_kw={'class': 'form-control'}
    )

    new_password2 = simple.PasswordField(
        label='确认新密码',
        validators=[DataRequired()],
        render_kw={'class': 'form-control'}
    )

    def validate_username(self, field):
        user = User.query.filter_by(username=field.data).first()
        if not user:
            raise validators.ValidationError('用户名不存在')