コード例 #1
0
def login():
    global AUTHORIZE

    form = LoginForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        user = db_sess.query(User).filter(
            User.email == form.email.data).first()
        if user and user.check_password(form.password.data):
            login_user(user, remember=form.remember_me.data)
            AUTHORIZE = 'Профиль'
            return redirect("/profile")
        return render_template('login.html', autho=AUTHORIZE,
                               title='Результаты',
                               message="Неправильный логин или пароль",
                               form=form)
    if request.method == 'POST':
        if request.form['submit_button'] == HOME:
            return redirect(url_for("index"))
        if request.form['submit_button'] == AUTHORIZE:
            if AUTHORIZE == 'Профиль':
                return redirect(url_for("profile"))
            elif AUTHORIZE == 'Авторизация':
                return redirect(url_for("login"))
    return render_template('login.html', autho=AUTHORIZE,
                           title='Авторизация', form=form)
コード例 #2
0
ファイル: main.py プロジェクト: Demitry0-0/project_servre
def login():
    form = LoginForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        user = session.query(User).filter(User.email == form.email.data).first()
        if user and user.check_password(form.password.data):
            login_user(user, remember=form.remember_me.data)
            return redirect("/")
        return render_template('login.html',
                               message="Неправильный логин или пароль",
                               form=form)
    return render_template('login.html', title='Авторизация', form=form)