Add invalid email or password message

main
sudoer777 2021-11-24 21:22:17 -07:00
parent ebef80e061
commit 24197d9bff
5 changed files with 24 additions and 3 deletions

4
app.js
View File

@ -7,6 +7,7 @@ var random = require('./database/accounts/random');
const passport = require('passport'); const passport = require('passport');
const session = require('express-session'); const session = require('express-session');
const accounts = require('./database/accounts/accounts'); const accounts = require('./database/accounts/accounts');
var flash = require('connect-flash');
var indexRouter = require('./routes/index'); var indexRouter = require('./routes/index');
@ -18,6 +19,9 @@ var adminRouter = require('./routes/admin');
var app = express(); var app = express();
// flash setup
app.use(flash());
// session setup // session setup
app.use( app.use(
session({ session({

14
package-lock.json generated
View File

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"async": "^3.2.2", "async": "^3.2.2",
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
"connect-flash": "^0.1.1",
"cookie-parser": "~1.4.3", "cookie-parser": "~1.4.3",
"debug": "~2.6.9", "debug": "~2.6.9",
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
@ -430,6 +431,14 @@
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
}, },
"node_modules/connect-flash": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/connect-flash/-/connect-flash-0.1.1.tgz",
"integrity": "sha1-2GMPJtlaf4UfmVax6MxnMvO2qjA=",
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/console-control-strings": { "node_modules/console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
@ -2554,6 +2563,11 @@
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
}, },
"connect-flash": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/connect-flash/-/connect-flash-0.1.1.tgz",
"integrity": "sha1-2GMPJtlaf4UfmVax6MxnMvO2qjA="
},
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",

View File

@ -9,6 +9,7 @@
"dependencies": { "dependencies": {
"async": "^3.2.2", "async": "^3.2.2",
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
"connect-flash": "^0.1.1",
"cookie-parser": "~1.4.3", "cookie-parser": "~1.4.3",
"debug": "~2.6.9", "debug": "~2.6.9",
"dotenv": "^10.0.0", "dotenv": "^10.0.0",

View File

@ -5,7 +5,7 @@ const accounts = require('./../database/accounts/accounts');
const app = require('../app'); const app = require('../app');
router.get('/login', (req, res, next) => { router.get('/login', (req, res, next) => {
res.render('accounts/login', { title : "Login" }); res.render('accounts/login', { title : "Login", message: req.flash('error') });
}); });
router.get('/logout', (req, res, next) => { router.get('/logout', (req, res, next) => {
@ -15,8 +15,9 @@ router.get('/logout', (req, res, next) => {
router.post('/login', router.post('/login',
passport.authenticate('local', { passport.authenticate('local', {
failureRedirect: '/fail', failureRedirect: '/auth/login',
successRedirect: '/success', successRedirect: '/',
failureFlash: "Invalid email or password.",
}), }),
(req, res, next) => { (req, res, next) => {
console.log(req.user); console.log(req.user);

View File

@ -16,5 +16,6 @@ block content
label Password label Password
span(class='form-section-input') span(class='form-section-input')
input(type="password", name="password") input(type="password", name="password")
.error #{message}
span(class='form-section') span(class='form-section')
button#submit-button(type="submit") Submit button#submit-button(type="submit") Submit