mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Allow username for login
This commit is contained in:
parent
ba3f9ec214
commit
50746ab821
@ -6,7 +6,7 @@ from wtforms.validators import DataRequired, Email, EqualTo, Length, Regexp
|
||||
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
email = StringField('Email', validators=[DataRequired(), Email()])
|
||||
user = StringField('Email or username', validators=[DataRequired()])
|
||||
password = PasswordField('Password', validators=[DataRequired()])
|
||||
remember_me = BooleanField('Keep me logged in')
|
||||
submit = SubmitField('Log In')
|
||||
|
@ -30,14 +30,16 @@ def login():
|
||||
return redirect(url_for('main.dashboard'))
|
||||
login_form = LoginForm(prefix='login-form')
|
||||
if login_form.validate_on_submit():
|
||||
user = User.query.filter_by(email=login_form.email.data).first()
|
||||
user = User.query.filter_by(username=login_form.user.data).first()
|
||||
if user is None:
|
||||
user = User.query.filter_by(email=login_form.user.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 email or password.')
|
||||
flash('Invalid email/username or password.')
|
||||
return render_template('auth/login.html.j2', login_form=login_form,
|
||||
title='nopaque')
|
||||
|
||||
|
@ -9,11 +9,13 @@ from . import main
|
||||
def index():
|
||||
login_form = LoginForm(prefix='login-form')
|
||||
if login_form.validate_on_submit():
|
||||
user = User.query.filter_by(email=login_form.email.data).first()
|
||||
user = User.query.filter_by(username=login_form.user.data).first()
|
||||
if user is None:
|
||||
user = User.query.filter_by(email=login_form.user.data).first()
|
||||
if user is not None and user.verify_password(login_form.password.data):
|
||||
login_user(user, login_form.remember_me.data)
|
||||
return redirect(url_for('main.dashboard'))
|
||||
flash('Invalid email or password.')
|
||||
flash('Invalid email/username 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.email(class='validate') }}
|
||||
{{ login_form.email.label }}
|
||||
{% for error in login_form.email.errors %}
|
||||
{{ login_form.user(class='validate') }}
|
||||
{{ login_form.user.label }}
|
||||
{% for error in login_form.user.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -100,9 +100,9 @@
|
||||
{{ login_form.hidden_tag() }}
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ login_form.email(class='validate') }}
|
||||
{{ login_form.email.label }}
|
||||
{% for error in login_form.email.errors %}
|
||||
{{ login_form.user(class='validate') }}
|
||||
{{ login_form.user.label }}
|
||||
{% for error in login_form.user.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user