Beispiel #1
0
def login():
    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)
            flash('Login Successful')
            return redirect(url_for("index"))
        else:
            flash('Login Unsuccessful')
    return render_template('login.html', title='Login', form=form)
Beispiel #2
0
def login():
    form = LoginForm()
    if request.method == "POST":
        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)
                return redirect(url_for('index'))
            else:
                flash("Authentication failed !")
                app.logger.error('"Authentication failed !"')
    return render_template('login.html', title='Login', form=form)
Beispiel #3
0
def login():
    # register()
    if current_user.is_authenticated:
        return redirect(url_for('sales'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.user_name.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            flash(f'{form.user_name.data}登陆成功', 'success')
            return redirect(url_for('sales'))
        else:
            flash('密码错误', 'danger')
    return render_template('login.html', title='西臣小店-登陆', form=form)
Beispiel #4
0
def login():
    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)
            #If we access /post without being logged in then @login_required dec redirects us to login page, By doing this, it will add a query string 'next' argument to this URL i.e. URL /login?next=/post
            #here after login we directly want to access /post so next_page variable will have '/post' value
            next_page = request.args.get('next')
            #if next_page is empty that means normal login and next_page is /profile not /post since we are logging in
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('profile', user_name=user.username)
            return redirect(next_page)
            flash('Login Successful ')
            app.logger.debug('Login successful for user: '******'login'))
    return render_template('login.html', title='login', form=form)