Fix some bugs

This commit is contained in:
Patrick Jentsch
2020-02-19 16:36:55 +01:00
parent 75329382ab
commit 48685e4da6
6 changed files with 15 additions and 18 deletions

View File

@ -1,6 +1,6 @@
from app.auth.forms import LoginForm
from app.models import User
from flask import flash, redirect, render_template, request, url_for
from flask import flash, redirect, render_template, url_for
from flask_login import login_required, login_user
from . import main
@ -9,14 +9,11 @@ from . import main
def index():
login_form = LoginForm(prefix='login-form')
if login_form.validate_on_submit():
user = User.query.filter_by(username=login_form.user.data).first()
user = User.query.filter_by(email=login_form.email.data).first()
if user is not None and user.verify_password(login_form.password.data):
login_user(user, login_form.remember_me.data)
next = request.args.get('next')
if next is None or not next.startswith('/'):
next = url_for('main.dashboard')
return redirect(next)
flash('Invalid username or password.')
return redirect(url_for('main.dashboard'))
flash('Invalid email or password.')
return render_template('main/index.html.j2', login_form=login_form,
title='nopaque')