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

@ -6,7 +6,7 @@ from wtforms.validators import DataRequired, Email, EqualTo, Length, Regexp
class LoginForm(FlaskForm): class LoginForm(FlaskForm):
user = StringField('Username', validators=[DataRequired(), Length(1, 64)]) email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()]) password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Keep me logged in') remember_me = BooleanField('Keep me logged in')
submit = SubmitField('Log In') submit = SubmitField('Log In')

View File

@ -24,18 +24,18 @@ def before_request():
return redirect(url_for('auth.unconfirmed')) return redirect(url_for('auth.unconfirmed'))
@auth.route('/login') @auth.route('/login', methods=['GET', 'POST'])
def login(): def login():
login_form = LoginForm(prefix='login-form') login_form = LoginForm(prefix='login-form')
if login_form.validate_on_submit(): 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): if user is not None and user.verify_password(login_form.password.data):
login_user(user, login_form.remember_me.data) login_user(user, login_form.remember_me.data)
next = request.args.get('next') next = request.args.get('next')
if next is None or not next.startswith('/'): if next is None or not next.startswith('/'):
next = url_for('main.dashboard') next = url_for('main.dashboard')
return redirect(next) return redirect(next)
flash('Invalid username or password.') flash('Invalid email or password.')
return render_template('auth/login.html.j2', login_form=login_form, return render_template('auth/login.html.j2', login_form=login_form,
title='nopaque') title='nopaque')

View File

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

View File

@ -14,9 +14,9 @@
{{ login_form.hidden_tag() }} {{ login_form.hidden_tag() }}
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">person</i> <i class="material-icons prefix">person</i>
{{ login_form.user(class='validate') }} {{ login_form.email(class='validate') }}
{{ login_form.user.label }} {{ login_form.email.label }}
{% for error in login_form.user.errors %} {% for error in login_form.email.errors %}
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -27,7 +27,7 @@
</div> </div>
</div> </div>
<div class="card-action right-align"> <div class="card-action right-align">
{{ form.submit(class='btn') }} {{ reset_password_form.submit(class='btn') }}
</div> </div>
</form> </form>
</div> </div>

View File

@ -100,9 +100,9 @@
{{ login_form.hidden_tag() }} {{ login_form.hidden_tag() }}
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">person</i> <i class="material-icons prefix">person</i>
{{ login_form.user(class='validate') }} {{ login_form.email(class='validate') }}
{{ login_form.user.label }} {{ login_form.email.label }}
{% for error in login_form.user.errors %} {% for error in login_form.email.errors %}
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>