Beispiel #1
0
def register_user():
    if current_user.is_authenticated:
        flash('You are already logged in')
        return redirect(url_for('main.display_books'))
    form = RegistrationForm()
    if form.validate_on_submit():
        User.create_user(user=form.name.data,
                         email=form.email.data,
                         password=form.password.data)
        flash('Registration Successful')
        return redirect(url_for('authentication.do_the_login'))

    return render_template('registration.html', form=form)
Beispiel #2
0
def auth_create():

    if request.method == "GET":
        return render_template("auth/createform.html", form=CreateForm())

    form = CreateForm(request.form)

    if not form.validate():
        return render_template("auth/createform.html",
                               form=form,
                               error="Syötä kenttiin vähintään 2 merkkiä")

    User.create_user(username=form.username.data, password=form.password.data)
    user = User.query.filter_by(username=form.username.data,
                                password=form.password.data).first()
    if not user:
        return render_template(
            "auth/createform.html",
            form=form,
            error="Käyttäjätunnuksen luominen ei onnistunut")

    login_user(user, remember=True)
    return redirect(url_for("index"))
Beispiel #3
0
from application import create_app, db  # from the application package __init__
from application.auth.models import User

if __name__ == '__main__':
    flask_app = create_app(
        'prod'
    )  # This is where we define the desired configuration using .py file in config directory
    with flask_app.app_context():
        db.create_all()
        if not User.query.filter_by(user_name="harry").first():
            User.create_user(user='******',
                             email='*****@*****.**',
                             password='******')
    flask_app.run()