From 1b37c6e7556a0a81b178f398ee41fe0de667ff6c Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 29 Sep 2017 10:39:38 +0200 Subject: [PATCH] Error message if login failed --- controllers/auth/templates/login.pug | 6 +++--- controllers/auth/views.js | 7 +++++++ templates/base.pug | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/controllers/auth/templates/login.pug b/controllers/auth/templates/login.pug index 64cf229..f5af6e3 100644 --- a/controllers/auth/templates/login.pug +++ b/controllers/auth/templates/login.pug @@ -1,12 +1,12 @@ extends ../../../templates/base.pug block content - if loginFailed - .alert - | Username or password incorrect. Please try again. .row .col .col + if loginFailed + .alert.alert-danger + | Username or password incorrect. Please try again. form(method="POST", action=getUrl("loginTarget")) .form-group input.form-control(type="text", name="username", placeholder="Username", autofocus) diff --git a/controllers/auth/views.js b/controllers/auth/views.js index a2ac0e8..006dcd4 100644 --- a/controllers/auth/views.js +++ b/controllers/auth/views.js @@ -19,6 +19,11 @@ module.exports.redirectIfNotLogged = function(redirectionPage, toDecorate) { } module.exports.login = function(req, res, render) { + if (req.session.loginFailed !== undefined) { + res.locals.loginFailed = req.session.loginFailed; + req.session.loginFailed = undefined; + req.session.save(); + } render('login.pug'); } @@ -46,6 +51,8 @@ module.exports.loginTarget = function(req, res, render) { res.redirect(getUrl(redirection)); } else { + req.session.loginFailed = true; + req.session.save(); res.redirect(getUrl('login')); } } diff --git a/templates/base.pug b/templates/base.pug index d924a78..de01d7d 100644 --- a/templates/base.pug +++ b/templates/base.pug @@ -42,6 +42,7 @@ html | Log out .container block content + script(src='/static/bootstrap/js/jquery.min.js') script(src='/static/bootstrap/js/popper.min.js') script(src='/static/bootstrap/js/bootstrap.min.js')