Пример #1
0
def register_page():
    #  create an instance of the Registration Form
    register_form = RegisterForm()

    # The validate_on_submit() method returns True when the form is submitted using the POST request and data is valid.
    if register_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(register_form.password.data).decode('utf-8')
        user = User(
                    username=register_form.username.data,
                    email=register_form.email.data,
                    password=register_form.password.data
                    )
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {register_form.username.data}! You are now able to log in.', category='success')
        return redirect(url_for('login_page'))

    # pass the form to the template in the same way as variables and data are passed to the template
    return render_template('register.html', title='Registration Page', register_form=register_form)
Пример #2
0
def register():
    if current_user.is_authenticated:
        return url_for('home')
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_pass = bycrpt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pass)
        db.session.add(user)
        db.session.commit()
        flash('Your Account has been created , Login Now')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)