From f9d526afe7dfbb7ef999ee6143b3ceb1037f19f5 Mon Sep 17 00:00:00 2001 From: x-zhq Date: Sun, 28 Jul 2024 15:31:02 -0400 Subject: [PATCH] =?UTF-8?q?bugfix=20=EF=BC=8C=20login=EF=BC=9A=20username?= =?UTF-8?q?=20does=20not=20exist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BensonController.js | 11 ++++++----- views/loginPage.ejs | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/controllers/BensonController.js b/controllers/BensonController.js index af0e218..d6e8915 100644 --- a/controllers/BensonController.js +++ b/controllers/BensonController.js @@ -18,7 +18,9 @@ const getLoginPageAction = (req, res) => { const loginPage = viewPaths.login; const fpath = path.join(__dirname, loginPage); - res.render(fpath, {}); + const message = req.session.message; + req.session.message = null; // clear the message after retrieving it + res.render(fpath, { message: message }); }; // access: /landing @@ -81,15 +83,14 @@ const postLoginAction = async (req, res) => { const name = req.body.name; const pass = req.body.password; const users = await getUserByUserName(name); - console.log("-------users ------------: "); - console.log(users); - - if( pass == users.password){ + if( users && pass == users.password){ console.log('login success.'); req.session.username = name; req.session.userLoggedIn = true; res.redirect('/order-list'); }else{ + //const message = encodeURIComponent(''); + req.session.message = 'user name or password incorrect, please try again.'; res.redirect('/login'); } } diff --git a/views/loginPage.ejs b/views/loginPage.ejs index f1e645d..e222fc5 100644 --- a/views/loginPage.ejs +++ b/views/loginPage.ejs @@ -31,6 +31,14 @@