Error message if login failed

This commit is contained in:
Thomas Forgione 2017-09-29 10:39:38 +02:00
parent aa88b397d8
commit 1b37c6e755
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
3 changed files with 11 additions and 3 deletions

View File

@ -1,12 +1,12 @@
extends ../../../templates/base.pug extends ../../../templates/base.pug
block content block content
if loginFailed
.alert
| Username or password incorrect. Please try again.
.row .row
.col .col
.col .col
if loginFailed
.alert.alert-danger
| Username or password incorrect. Please try again.
form(method="POST", action=getUrl("loginTarget")) form(method="POST", action=getUrl("loginTarget"))
.form-group .form-group
input.form-control(type="text", name="username", placeholder="Username", autofocus) input.form-control(type="text", name="username", placeholder="Username", autofocus)

View File

@ -19,6 +19,11 @@ module.exports.redirectIfNotLogged = function(redirectionPage, toDecorate) {
} }
module.exports.login = function(req, res, render) { 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'); render('login.pug');
} }
@ -46,6 +51,8 @@ module.exports.loginTarget = function(req, res, render) {
res.redirect(getUrl(redirection)); res.redirect(getUrl(redirection));
} else { } else {
req.session.loginFailed = true;
req.session.save();
res.redirect(getUrl('login')); res.redirect(getUrl('login'));
} }
} }

View File

@ -42,6 +42,7 @@ html
| Log out | Log out
.container .container
block content block content
script(src='/static/bootstrap/js/jquery.min.js') script(src='/static/bootstrap/js/jquery.min.js')
script(src='/static/bootstrap/js/popper.min.js') script(src='/static/bootstrap/js/popper.min.js')
script(src='/static/bootstrap/js/bootstrap.min.js') script(src='/static/bootstrap/js/bootstrap.min.js')