-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.txt
90 lines (67 loc) · 2.28 KB
/
script.txt
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//Отображение страницы enter
app.get('/enter', function (req, res) {
res.render('enter');
});
// POST /login gets urlencoded bodies
app.post('/enter', urlencodedParser, function (req, res) {
if(!req.body) return res.sendStatus(400)
var query = "SELECT * FROM users WHERE login='"+req.body.login+"' ";
//console.log(query);
connection.query(query, function (error, results, fields) {
if (error) throw error;
console.log(results);
if(results!=null){
if(results[0].password == req.body.pass){
var description = results[0].description;
res.render('me', {name: description});
}else
console.log("Ошибка входа");
res.render('enter');
}
}
});
//Отображение страницы register
app.get('/register', function (req, res) {
res.render('register');
});
// POST /login gets urlencoded bodies
app.post('/register', urlencodedParser, function (req, res) {
if(!req.body) return res.sendStatus(400)
console.log(req.body);
var query = "INSERT INTO users VALUES(null, '"+req.body.login+"', '"+req.body.pass+"', '"+req.body.des+"')";
//console.log(query);
connection.query(query, function (error, results, fields) {
if (error) throw error;
});
res.render('enter');
});
//Отображение страницы posts
app.get('/posts', function (req, res) {
var query="SELECT * FROM posts";
connection.query(query, function (error, results, fields) {
if (error) throw error;
console.log(results);
res.render('posts',{posts: results});
});
});
// POST /login gets urlencoded bodies
app.post('/posts', urlencodedParser, function (req, res) {
if(!req.body) return res.sendStatus(400)
console.log(req.body);
var query = "INSERT INTO posts VALUES(null, '"+req.body.topic+"', '"+req.body.description+"')";
//console.log(query);
connection.query(query, function (error, results, fields) {
if (error) throw error;
});
res.render('enter');
});
//Отображение страницы about
app.get('/about', function (req, res) {
res.render('about');
});
// POST /login gets urlencoded bodies
app.post('/about', urlencodedParser, function (req, res) {
if(!req.body) return res.sendStatus(400)
console.log(req.body);
res.render('about');
});