mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Fix some bugs
This commit is contained in:
parent
75329382ab
commit
48685e4da6
@ -6,7 +6,7 @@ from wtforms.validators import DataRequired, Email, EqualTo, Length, Regexp
|
||||
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
user = StringField('Username', validators=[DataRequired(), Length(1, 64)])
|
||||
email = StringField('Email', validators=[DataRequired(), Email()])
|
||||
password = PasswordField('Password', validators=[DataRequired()])
|
||||
remember_me = BooleanField('Keep me logged in')
|
||||
submit = SubmitField('Log In')
|
||||
|
@ -24,18 +24,18 @@ def before_request():
|
||||
return redirect(url_for('auth.unconfirmed'))
|
||||
|
||||
|
||||
@auth.route('/login')
|
||||
@auth.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
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.')
|
||||
flash('Invalid email or password.')
|
||||
return render_template('auth/login.html.j2', login_form=login_form,
|
||||
title='nopaque')
|
||||
|
||||
|
@ -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')
|
||||
|
||||
|
@ -14,9 +14,9 @@
|
||||
{{ login_form.hidden_tag() }}
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ login_form.user(class='validate') }}
|
||||
{{ login_form.user.label }}
|
||||
{% for error in login_form.user.errors %}
|
||||
{{ login_form.email(class='validate') }}
|
||||
{{ login_form.email.label }}
|
||||
{% for error in login_form.email.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -27,7 +27,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action right-align">
|
||||
{{ form.submit(class='btn') }}
|
||||
{{ reset_password_form.submit(class='btn') }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -100,9 +100,9 @@
|
||||
{{ login_form.hidden_tag() }}
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ login_form.user(class='validate') }}
|
||||
{{ login_form.user.label }}
|
||||
{% for error in login_form.user.errors %}
|
||||
{{ login_form.email(class='validate') }}
|
||||
{{ login_form.email.label }}
|
||||
{% for error in login_form.email.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user