-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathps_users.js
76 lines (69 loc) · 2.24 KB
/
ps_users.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
73
74
75
76
const mysqlconfig = require('./public/js/mysql_con.js');
var con = mysqlconfig.con;
const crypto = require("crypto");
function login(req, res, next){
var shasum = crypto.createHash("sha256");
var email = req.query.email;
shasum.update(req.query.pw);
var pw = shasum.digest("hex");
con.query(`select * from users where email = "${email}"`, function (err, result) {
if (err) throw err;
console.log(result);
if(result[0] === undefined){
res.send({
condition: "fail",
message: "존재하지 않는 이메일입니다."
});
}
else{
if(result[0].password === pw){
res.cookie("userEmail", email);
res.cookie("username", result[0].name);
res.send({
condition: "success",
message: "로그인되었습니다."
});
}
else{
res.send({
condition: "fail",
message: "비밀번호가 불일치합니다."
});
}
}
});
}
function logout(req, res, next){
res.cookie("userEmail", "");
res.sendFile('index.html', {root: __dirname});
}
function join(req, res, next){
var name = req.query.name;
var email = req.query.email;
var shasum = crypto.createHash("sha256");
shasum.update(req.query.pw)
var pw = shasum.digest("hex")
con.query(`select * from users where email = "${email}"`, function (err, result) {
if (err) throw err;
console.log(result);
if(result[0] === undefined){
con.query(`insert into users (name, email, password) values("${name}", "${email}", "${pw}")`, function (err, result) {
if(err) throw err;
console.log(result);
res.send({
condition: "join",
message: "회원가입이 완료되었습니다."
});
});
}
else{
res.send({
condition: "fail",
message: "이미 있는 유저입니다."
});
}
});
}
exports.login = login;
exports.join = join;
exports.logout = logout;