-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
65 lines (55 loc) · 1.27 KB
/
app.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
let users = [];
app.set('view engine' ,'ejs');
app.use(express.static('./views'));
app.set('views', __dirname + '/views');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}))
// GET REQ
app.get('/',(req , res)=>{
res.redirect('/login');
})
app.get('/login',(req , res)=>{
res.render('login')
})
app.get('/reg',(req , res)=>{
res.render('register')
})
app.get('/list', (req, res)=> {
res.render('list', {
arr: users
})
})
// POST REQ
app.post('/user/add', (req, res)=> {
let newUser = {
name: req.body.name,
email: req.body.email,
pass: req.body.pass,
phone: req.body.phone,
address: req.body.address,
}
users.push(newUser)
res.redirect('/');
})
app.post('/user/login', (req, res)=> {
let found = false
let loginUser = {
email: req.body.email,
pass: req.body.pass,
}
for (x of users) {
if(x.email == req.body.email && x.pass == req.body.pass) {
found = true
res.redirect('/list')
}
}
if (!found) {
res.redirect('/');
}
})
app.listen(3000, ()=>{
console.log('app is running at port 3000')
});