mirror of
https://github.com/simple-login/app.git
synced 2024-09-27 20:31:30 +02:00
use flash to display error in login
This commit is contained in:
parent
ea1492904a
commit
41fe528441
@ -15,10 +15,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block single_content %}
|
||||
{% if error %}
|
||||
<div class="text-danger text-center mb-4">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
<h1 class="h2 text-center">Welcome back!</h1>
|
||||
|
||||
<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_wtf import FlaskForm
|
||||
from wtforms import StringField, validators
|
||||
@ -21,19 +21,21 @@ def login():
|
||||
|
||||
form = LoginForm(request.form)
|
||||
next_url = request.args.get("next")
|
||||
error = ""
|
||||
show_resend_activation = False
|
||||
|
||||
if form.validate_on_submit():
|
||||
user = User.filter_by(email=form.email.data).first()
|
||||
|
||||
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):
|
||||
error = "Wrong password"
|
||||
flash("Wrong password", "error")
|
||||
elif not user.activated:
|
||||
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:
|
||||
LOG.debug("log user %s in", user)
|
||||
login_user(user)
|
||||
@ -51,5 +53,4 @@ def login():
|
||||
form=form,
|
||||
next_url=next_url,
|
||||
show_resend_activation=show_resend_activation,
|
||||
error=error,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user