Ejemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # Hash password
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pw)
        user.save()
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        u = User(username=form.username.data,
                 email=form.email.data,
                 password=hashed_password)
        u.save()
        # db.session.add(u)
        # db.session.commit()
        flash(f'Account created for {form.username.data}! Please login',
              'success')
        return redirect(url_for('users.login'))

    return render_template('register.html', title='Register', form=form)