コード例 #1
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrybt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            n_page = request.args.get("next")
            return redirect(n_page) if n_page else redirect(url_for("home"))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
コード例 #2
0
ファイル: routes.py プロジェクト: AdamGreed/lessons
def login():
    form = LoginForm()

    if current_user.is_authenticated:
        return redirect(url_for('index'))

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()

        if user is None or not user.check_password(form.password.data):
            flash('Неправильное имя пользователя и/или пароль', 'danger')
            return redirect(url_for('login'))

        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('index'))

    return render_template('login.html', title='Вход', form=form)
コード例 #3
0
ファイル: routes.py プロジェクト: PaulcPaul/flask-blog
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))

        flash('Login não foi possível. Verifique as credenciais.', 'danger')

    popular = Post.query.order_by(desc(Post.total_score)).limit(3)
    return render_template('login.html',
                           title='Login',
                           form=form,
                           popular_posts=popular)