Showing
2 changed files
with
32 additions
and
2 deletions
... | @@ -105,4 +105,26 @@ router.post('/update', function(req,res,next){ | ... | @@ -105,4 +105,26 @@ router.post('/update', function(req,res,next){ |
105 | }) | 105 | }) |
106 | }) | 106 | }) |
107 | 107 | ||
108 | +router.post('/delete', function(req,res,next){ | ||
109 | + var idx = req.body.idx | ||
110 | + var passwd = req.body.passwd | ||
111 | + var datas = [idx,passwd] | ||
112 | + | ||
113 | + var sql = "delete from board where idx=? and passwd=?" | ||
114 | + | ||
115 | + board.query(sql,datas, function(err,result){ | ||
116 | + if(err) console.error(err) | ||
117 | + if(result.affectedRows == 0){ | ||
118 | + res.send("<script>alert('패스워드가 일치하지 않습니다.');history.back();</script>"); | ||
119 | + } | ||
120 | + else | ||
121 | + { | ||
122 | + var id = req.user.ID; | ||
123 | + var nickname = req.user.nickname; | ||
124 | + console.log(req.user.ID+'('+nickname+') 유저가 '+idx+'번 게시글을 삭제했습니다.') | ||
125 | + res.redirect('/board/list/'); | ||
126 | + } | ||
127 | + }) | ||
128 | +}) | ||
129 | + | ||
108 | module.exports = router; | 130 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -31,7 +31,13 @@ | ... | @@ -31,7 +31,13 @@ |
31 | </nav> | 31 | </nav> |
32 | <div class="container px-5 my-5"> | 32 | <div class="container px-5 my-5"> |
33 | <h1><%= title %></h1> | 33 | <h1><%= title %></h1> |
34 | - | 34 | + <script> |
35 | + function submit2(frm){ | ||
36 | + frm.action="/board/delete"; | ||
37 | + frm.submit(); | ||
38 | + return true; | ||
39 | + } | ||
40 | + </script> | ||
35 | <form action="/board/update" method="post"> | 41 | <form action="/board/update" method="post"> |
36 | <table border="1"> | 42 | <table border="1"> |
37 | <input type="hidden" name="idx" value="<%=row.idx%>"/> | 43 | <input type="hidden" name="idx" value="<%=row.idx%>"/> |
... | @@ -64,8 +70,9 @@ | ... | @@ -64,8 +70,9 @@ |
64 | <td><%=row.hit%></td> | 70 | <td><%=row.hit%></td> |
65 | </tr> | 71 | </tr> |
66 | <tr> | 72 | <tr> |
67 | - <td colspan="2"> | 73 | + <td colspan="3"> |
68 | <button type="submit">글 수정</button> | 74 | <button type="submit">글 수정</button> |
75 | + <button type="summit" onclick="return submit2(this.form);">글 삭제</button> | ||
69 | <a href="/board/list">목록</a> | 76 | <a href="/board/list">목록</a> |
70 | </td> | 77 | </td> |
71 | </tr> | 78 | </tr> |
... | @@ -102,6 +109,7 @@ | ... | @@ -102,6 +109,7 @@ |
102 | </ul> | 109 | </ul> |
103 | </div> | 110 | </div> |
104 | </div> | 111 | </div> |
112 | + | ||
105 | </div> | 113 | </div> |
106 | </footer> | 114 | </footer> |
107 | </body> | 115 | </body> | ... | ... |
-
Please register or login to post a comment