示例#1
0
def register():
    if User.query.first():
        return redirect(url_for('auth.login'))

    if current_user.is_authenticated:
        return redirect(url_for('messages.read'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, password=generate_password_hash(form.password.data))
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
示例#2
0
def registration():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data.lower(),
                    password=hashed_pw,
                    image_file='default_' + str(random.randrange(1, 4, 1)) +
                    '.jpg')

        db.session.add(user)
        db.session.commit()

        #flash('Your account has been  created you can now login', 'success')
        return redirect(url_for('login'))
    return render_template('registration.html',
                           title='Registration',
                           form=form)