diff --git a/app.js b/app.js index d21b9483ce20b0b2f03676d73528a41cc405fc80..4a17df52ba3378c39030c19edbc6e7aba92c464b 100644 --- a/app.js +++ b/app.js @@ -68,6 +68,8 @@ app.get('/register', (req, res) => { res.sendFile(path.join(__dirname, 'public', 'register.html')); }); + + app.post('/register', async (req, res) => { const { email, password } = req.body; @@ -142,6 +144,10 @@ app.post('/login', async (req, res) => { } }); +app.use(express.json()); // สำหรับการ parse ข้อมูลแบบ JSON +app.use(express.urlencoded({ extended: true })); // สำหรับการ parse ข้อมูลแบบ URL-encoded + + app.post('/logout', (req, res) => { req.session.destroy(err => { if (err) { diff --git a/public/login.html b/public/login.html index b21ff986d1f1cee9d00d2afa363bbcd67690a895..417e318fddcfa7d061c51089c0fc9e326dcc5cb7 100644 --- a/public/login.html +++ b/public/login.html @@ -9,9 +9,9 @@ <body> <div class="login-container"> <h2>Login</h2> - <form action="/login" method="post"> - <input type="text" placeholder="Username" name="user" required> - <input type="password" placeholder="Password" name="password" required> + <form method="POST" action="/login"> + <input type="email" placeholder="Email" name="email" required /> + <input type="password" placeholder="Password" name="password" required /> <button type="submit">Login</button> <p>don't have account <a href="register.html">Register</a></p> </form>