예제 #1
0
def signin():
    form = UserLoginForm()
    try:
        if request.method == 'POST' and form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            print(email, password)

            logged_user = User.query.filter(User.email == email).first()
            if logged_user and check_password_hash(logged_user.password, password):
                login_user(logged_user)
                flash('You were successfully logged in: Via Email/Password', 'auth-success')
                return redirect(url_for('home'))
            else:
                flash('Your Email/Password is incorrect', 'auth-failed')
                return redirect(url_for('signin'))
    except:
        raise Exception('Invalid For Data: Please Check your form')

    return render_template('signin.html', form=form)
예제 #2
0
def signin():
    form = UserLoginForm()

    if request.method == 'POST' and form.validate_on_submit():
        # 'here' = form.'here'.data
        email = form.email.data
        password = form.password.data
        print(email, password)

        logged_user = User.query.filter(User.username == email).first()
        if logged_user and check_password_hash(logged_user.password, password):
            login_user(logged_user)
            flash('You were successfully logged in: Via Email/Password',
                  'auth-success')
            return redirect(url_for('base'))
        else:
            flash('Your Email/Password is incorrect', 'auth-failed')
            return redirect(url_for('signin'))
    else:
        flash('Invalid form', 'invalid-form')

    return render_template('signin.html', form=form)