From bdabf532b1b97224fb9430bb990017d0dc2878b1 Mon Sep 17 00:00:00 2001 From: 65160381 <65160381@go.buu.ac.th> Date: Tue, 25 Mar 2025 01:13:18 +0700 Subject: [PATCH] 7.6 --- app.js | 6 ++++++ public/login.html | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index d21b948..4a17df5 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 b21ff98..417e318 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> -- GitLab