@app.route('/login', methods=['GET', 'POST'])
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')
            if next_page:
                return (redirect(next_page) if next_page else redirect(url_for('home')))
            else:
                return redirect(url_for('account'))
        else:
            flash(f'Login Unsuccessful...Please check email and password!', 'danger')
    return render_template('login.html', title='Login', form=form)
@app.route('/login', methods=['GET', 'POST'])
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')
            if next_page:
                return (redirect(next_page) if next_page else redirect(url_for('home')))
            else:
                return redirect(url_for('account'))
        else:
            flash(f'Login Unsuccessful...Please check email and password!', 'danger')
    return render_template('login.html', title='Login', form=form)