Skip to content
Snippets Groups Projects
Commit 37bd8177 authored by Mart van Santen's avatar Mart van Santen
Browse files

First error handling in backend

parent 2650b98e
No related branches found
No related tags found
1 merge request!105Resolve "Fix error messages kratos during login"
Pipeline #38604 passed with stages
in 3 minutes and 38 seconds
......@@ -130,13 +130,28 @@ def login():
# Check if we are logged in:
identity = get_auth()
error_message = ""
error = False
refresh = False
flow = request.args.get("flow")
if flow:
cookies = request.headers['cookie']
flow = kratos_public_frontend_api.get_login_flow(flow, cookie=cookies)
refresh = flow['refresh']
try:
for msg in flow.ui.messages.value:
if msg.id == 4000006:
error_message = "The provided login e-mail address or password is incorrect. Please try again."
error = True
else:
if msg.type == 'error':
error_message = msg.text
error = True
else:
current_app.logger.info("Kratos message:" + msg.text)
except Exception as ex:
current_app.logger.error(ex)
if identity and not refresh:
# We are already logged in, and don't need to refresh.
......@@ -146,7 +161,10 @@ def login():
name = " " + identity['traits']['name']
else:
name = ""
return render_template("loggedin.html", api_url=KRATOS_PUBLIC_URL, dashboard_url=DASHBOARD_URL, name=name)
return render_template("loggedin.html",
api_url=KRATOS_PUBLIC_URL,
dashboard_url=DASHBOARD_URL,
name=name)
# If we do not have a flow, get one.
if not flow:
......@@ -161,7 +179,9 @@ def login():
# or `not identity`
# User is not logged in yet.
# In either case, we present the login screen now.
return render_template("login.html", api_url=KRATOS_PUBLIC_URL, dashboard_url=DASHBOARD_URL, refresh=refresh, demo=DEMO_INSTANCE)
return render_template("login.html", api_url=KRATOS_PUBLIC_URL,
dashboard_url=DASHBOARD_URL, refresh=refresh, error=error,
error_message=error_message, demo=DEMO_INSTANCE)
@web.route("/auth", methods=["GET", "POST"])
......
......@@ -14,6 +14,9 @@
</script>
{% if error %}
<div class="alert alert-danger">{{ error_message }}</div>
{% endif %}
{% if refresh %}
<div class="alert alert-warning">Please confirm your credentials to complete this action.</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment