-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (57 loc) · 1.42 KB
/
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
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
66
67
68
69
70
71
72
/**
* Created by sayla on 2/12/2015.
*/
var express = require("express");
var bodyParser = require("body-parser");
var cors = require("cors");
var allUsers = [
{
email: "malikasinger@gmail.com",
password: "pakistan",
adminStatus: 'admin'
},
{
email: "admin@admin.com",
password: "admin",
adminStatus: 'admin'
},
{
email: "user@user.com",
password: "user",
adminStatus: 'user'
}
];
var app = express();
app.use(cors());
app.use(bodyParser.json({}));
app.post("/login", function (req, res) {
var logedin = null;
console.log("post hitted " + logedin);
for (var i = 0; i < allUsers.length; i++) {
if (req.body.email == allUsers[i].email) {
if (req.body.password == allUsers[i].password) {
logedin = i;
console.log(allUsers[i].email + " " + allUsers[i].password);
break;
}
}
}
if (logedin != null) {
res.json({
status: "signed in",
as: allUsers[logedin].email,
adminStatus: allUsers[logedin].adminStatus
});
} else {
res.json({
status: "Email or Password not matched"
})
}
});
app.get("/login", function (req, res) {
console.log("get login hitted");
res.end();
});
app.listen(3000, function () {
console.log("listening at: 3000")
});