-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (43 loc) · 1.16 KB
/
server.js
File metadata and controls
55 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const express = require('express');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.send(`
<h1>Login Page</h1>
<form method="POST" action="/login">
<div>
<label>Email</label>
<input name="email" aria-label="Email" />
</div>
<div>
<label>Password</label>
<input name="password" type="password" aria-label="Password" />
</div>
<button type="submit">Login</button>
</form>
`);
});
app.post('/login', (req, res) => {
const { email, password } = req.body;
if (!email || !password) {
return res.send(`
<h1>Login Page</h1>
<p style="color:red;">Email and password are required</p>
<a href="/">Try Again</a>
`);
}
if (email !== 'user@example.com' || password !== 'password') {
return res.send(`
<h1>Login Page</h1>
<p style="color:red;">Invalid credentials</p>
<a href="/">Try Again</a>
`);
}
res.redirect('/dashboard');
});
app.get('/dashboard', (req, res) => {
res.send(`<h1>Dashboard</h1>`);
});
app.listen(3000, () => {
console.log('Server running at http://localhost:3000');
});