use flash to display error in login
This commit is contained in:
parent
ea1492904a
commit
41fe528441
|
@ -15,10 +15,6 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block single_content %}
|
{% block single_content %}
|
||||||
{% if error %}
|
|
||||||
<div class="text-danger text-center mb-4">{{ error }}</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<h1 class="h2 text-center">Welcome back!</h1>
|
<h1 class="h2 text-center">Welcome back!</h1>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import request, render_template, redirect, url_for
|
from flask import request, render_template, redirect, url_for, flash
|
||||||
from flask_login import login_user, current_user
|
from flask_login import login_user, current_user
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import StringField, validators
|
from wtforms import StringField, validators
|
||||||
|
@ -21,19 +21,21 @@ def login():
|
||||||
|
|
||||||
form = LoginForm(request.form)
|
form = LoginForm(request.form)
|
||||||
next_url = request.args.get("next")
|
next_url = request.args.get("next")
|
||||||
error = ""
|
|
||||||
show_resend_activation = False
|
show_resend_activation = False
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = User.filter_by(email=form.email.data).first()
|
user = User.filter_by(email=form.email.data).first()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
error = "Email not exist in our system"
|
flash("Email not exist in our system", "error")
|
||||||
elif not user.check_password(form.password.data):
|
elif not user.check_password(form.password.data):
|
||||||
error = "Wrong password"
|
flash("Wrong password", "error")
|
||||||
elif not user.activated:
|
elif not user.activated:
|
||||||
show_resend_activation = True
|
show_resend_activation = True
|
||||||
error = "Please check your inbox for the activation email. You can also have this email re-sent"
|
flash(
|
||||||
|
"Please check your inbox for the activation email. You can also have this email re-sent",
|
||||||
|
"error",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
LOG.debug("log user %s in", user)
|
LOG.debug("log user %s in", user)
|
||||||
login_user(user)
|
login_user(user)
|
||||||
|
@ -51,5 +53,4 @@ def login():
|
||||||
form=form,
|
form=form,
|
||||||
next_url=next_url,
|
next_url=next_url,
|
||||||
show_resend_activation=show_resend_activation,
|
show_resend_activation=show_resend_activation,
|
||||||
error=error,
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue