-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 944 Bytes
/
index.js
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
const express = require('express');
const session = require('express-session');
const parser = require('body-parser').urlencoded({ extended: false });
const app = express();
app.use(session({
secret: 'keyboard cat',
cookie: { maxAge: 60000 },
resave: true,
saveUninitialized: true
}));
app.listen(3000, () => console.log('Server started'));
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.set('views', './views');
app.get('/check', (req, res) => {
if (req.session.daDangNhap) return res.send('DA_DANG_NHAP');
res.send('CHUA_DANG_NHAP');
});
app.get('*', (req, res) => res.render('home'));
app.post('/dangnhap', parser, (req, res) => {
const { username, password } = req.body;
if (username === 'pho' && password === '123') {
req.session.daDangNhap = true; // eslint-disable-line
return res.send('DANG_NHAP_THANH_CONG');
}
res.send('DANG_NHAP_THAT_BAI');
});