-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest.js
63 lines (56 loc) · 1.76 KB
/
rest.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
var mysql = require("mysql");
function REST_ROUTER(router, connection, md5) {
var self = this;
self.handelRoutes(router, connection, md5);
}
REST_ROUTER.prototype.handelRoutes = function(router, connection, md5) {
router.get("/", function(req, res) {
res.json({
"message": "hello world"
});
});
router.post("/login", function(req, res) {
var user = req.body.username;
var passsword = req.body.passsword;
var query = "SELECT * FROM log WHERE ??=?";
var table = ["username", user];
query = mysql.format(query, table);
connection.query(query, function(error, results) {
if (error) {
// res.json({"error":true,
// "message":"error executing the mysql query"});
console.log(error);
} else {
res.json({
"error": false,
"message": "Success",
"users": results
});
}
});
});
router.post("/signup", function(req, res) {
var user = {
id: req.body.id,
username: req.body.username,
password: req.body.password,
email: req.body.email
};
var query = "INSERT INTO log set ?";
var table = [user];
query = mysql.format(query, table);
connection.query(query, function(error, results) {
if (error) { // res.json({"error":true,
// "message":"error executing the mysql query"});
console.log(error);
} else {
res.json({
"error": false,
"message": "Success",
"users": results
});
}
});
});
}
module.exports = REST_ROUTER;