박기범
...@@ -20,19 +20,40 @@ router.post('/update', function(req, res, next) { ...@@ -20,19 +20,40 @@ router.post('/update', function(req, res, next) {
20 console.log("updating user failed"); 20 console.log("updating user failed");
21 next(err); 21 next(err);
22 } else { 22 } else {
23 - console.log("user updated successfully"); 23 + res.status(200).send('update');
24 - res.redirect('back');
25 } 24 }
26 }); 25 });
27 } 26 }
28 else 27 else
29 { 28 {
30 - console.log("password not match"); 29 + res.status(404).send(err);
31 - res.redirect('back');
32 } 30 }
33 }); 31 });
34 32
33 +router.post('/delete', function(req, res, next) {
34 + var user_id=req.body.user_id;
35 + var user_pw=req.body.user_pw;
36 + var user_pw_temp =cryptoM.encrypt(user_pw); //받아온 비밀번호를 암호화화여 임시변수에 저장
37 +
38 + var sqlquery = "SELECT user_pw FROM users WHERE user_id = ?"; // user_id의 비밀번호를 가져옴
39 + connection.query(sqlquery, [user_id], function (err, rows) {
40 + if (rows[0].user_pw == user_pw_temp) { // 받아온 비밀번호와 user_id의 비밀번호가 같은지 대조
41 + var sql = 'delete from users where user_id = ?'; // 만약 같다면 삭제 진행
42 + var values = [user_id];
43 + connection.query(sql, values, function (err) {
44 + if (err) {
45 + console.log("delete user failed");
46 + throw err;
47 + } else {
48 + res.status(200).send('delete');
35 49
50 + }
51 + });
52 + } else {
53 + res.status(404).send(err);
54 + }
55 + });
36 56
57 +});
37 58
38 module.exports = router; 59 module.exports = router;
......