コード例 #1
0
ファイル: routes.py プロジェクト: LongZhai/flask
def register():
    db.drop_all()
    db.create_all()
    hashed_password = bcrypt.generate_password_hash('22888').decode('utf-8')
    user = User(username='******',
                email='*****@*****.**',
                password=hashed_password)
    db.session.add(user)
    db.session.commit()
コード例 #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pwd = bcrypt.generate_password_hash(form.password.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pwd)
        db.session.add(user)
        db.session.commit()
        flash('Registraion Successfull !!')
        return redirect(url_for('login'))
    elif form.errors:
        flash("Registration unsuccessful. Please try again")
        return redirect(url_for('register'))
    return render_template('register.html', title='register', form=form)
コード例 #3
0
def register():
    form = RegistrationForm()
    if request.method == "POST":
        if form.validate_on_submit():
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
            db.session.add(user)
            db.session.commit()
            flash("Account created !")
            return redirect(url_for('login'))
        if form.errors:
            flash("Validation Errors:" + str(form.errors))
            app.logger.error('ValidationError:\n' + str(form.errors))
    return render_template('register.html', title='Register', form=form)
コード例 #4
0
def register():
    if (current_user.is_authenticated):
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Account created !')
        return redirect(url_for('login'))

    if form.errors:
        flash('Validation Errors: ' + str(form.errors))
        app.logger.error('ValidationError:\n' + str(form.errors))

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