Skip to content

Commit ed5bdf7

Browse files
authored
feat:lesson_24 added signup page for CD Website Tommy Tran (#592)
1 parent c6e331e commit ed5bdf7

File tree

9 files changed

+1301
-0
lines changed

9 files changed

+1301
-0
lines changed

lesson_24/tommytran/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const express = require ('express');
2+
const morgan = require ('morgan');
3+
const path = require('path');
4+
const app = express();
5+
6+
app.use(morgan('dev'));
7+
app.use(express.static(path.join(__dirname,'public')));
8+
9+
const PORT = process.env.PORT || 3000;
10+
11+
app.use(express.urlencoded({ extended: true }));
12+
13+
app.post('/signup', (req, res) => {
14+
const signupData = {
15+
name: req.body.name,
16+
email: req.body.email,
17+
password: req.body.password,
18+
confirmPassword: req.body['confirm-password']
19+
};
20+
21+
if (signupData.password !== signupData.confirmPassword) {
22+
return res.status(400).send('Passwords do not match.');
23+
}
24+
// Redirect to a new page, passing data via query string
25+
res.redirect(`/welcome?name=${encodeURIComponent(signupData.name)}&email=${encodeURIComponent(signupData.email)}`);
26+
});
27+
28+
app.get('/welcome', (req, res) => {
29+
const name = req.query.name;
30+
const email = req.query.email;
31+
32+
// Render the welcome page with the signup information
33+
res.send(`
34+
<h1>Welcome,${name}</h1>
35+
<p>Your email: ${email}</p>
36+
<p>Your password is processed</p>
37+
`);
38+
});
39+
40+
app.listen (PORT, ()=>{
41+
console.log(`Server is running on port ${PORT}`);
42+
}
43+
);

0 commit comments

Comments
 (0)