Skip to content

Commit

Permalink
bugfix , login: username does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
x-zhq committed Jul 28, 2024
1 parent 53a1a96 commit f9d526a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions controllers/BensonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
Expand Down
8 changes: 8 additions & 0 deletions views/loginPage.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
<main>
<section class="tour-details">
<div class="login">
<% if (message) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<%= message %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<% } %>
<div class="container">
<div class="login-container">
<div class="login-title">Login to your account</div>
Expand Down

0 comments on commit f9d526a

Please sign in to comment.