unknown

myprof

...@@ -33,7 +33,7 @@ CREATE TABLE `board` ( ...@@ -33,7 +33,7 @@ CREATE TABLE `board` (
33 `passwd` varchar(50) NOT NULL, 33 `passwd` varchar(50) NOT NULL,
34 `hit` int(11) NOT NULL DEFAULT '0', 34 `hit` int(11) NOT NULL DEFAULT '0',
35 PRIMARY KEY (`idx`) 35 PRIMARY KEY (`idx`)
36 -); 36 +);<br><br>
37 37
38 DB구조 - board에서 사용됨(*idx, name, title, content, regdate, modidate, passwd, hit)<br> 38 DB구조 - board에서 사용됨(*idx, name, title, content, regdate, modidate, passwd, hit)<br>
39 *idx int, name varchar(50), title varchar(50), content mediumtext, regdate datetime, modidate datetime, passwd varchar(50), hit int<br> 39 *idx int, name varchar(50), title varchar(50), content mediumtext, regdate datetime, modidate datetime, passwd varchar(50), hit int<br>
...@@ -42,6 +42,6 @@ DB구조 - board에서 사용됨(*idx, name, title, content, regdate, modidate, ...@@ -42,6 +42,6 @@ DB구조 - board에서 사용됨(*idx, name, title, content, regdate, modidate,
42 LF 오류시 git config --global core.autocrlf true 입력<br><br> 42 LF 오류시 git config --global core.autocrlf true 입력<br><br>
43 43
44 44
45 -최종 수정: 2021-11-18 20:03<br> 45 +최종 수정: 2021-11-19 12:19<br>
46 -최종 수정 내용: 메뉴바/하단 추가, 게시판에 기본 서식 추가, 로그인시에만 게시판 관련 경로에 접근가능하게 함, 사용자 로그 생성 46 +최종 수정 내용: 메뉴바/하단 추가, 게시판에 기본 서식 추가, 로그인시에만 게시판 관련 경로에 접근가능하게 함, 사용자 로그 생성<br>
47 수정 내용: 경로 지정 수정, 제목 추가, userDB, 회원가입에 nickname요소 추가, 세션에 ID + 닉네임 전달기능 추가, 게시판의 글쓰기 및 글 열람 기능 추가. 47 수정 내용: 경로 지정 수정, 제목 추가, userDB, 회원가입에 nickname요소 추가, 세션에 ID + 닉네임 전달기능 추가, 게시판의 글쓰기 및 글 열람 기능 추가.
......
1 +const { WSAECONNRESET } = require('constants');
1 const e = require('express'); 2 const e = require('express');
2 var express = require('express'); 3 var express = require('express');
3 const { connect } = require('http2'); 4 const { connect } = require('http2');
...@@ -14,18 +15,23 @@ router.get('/list/:page', function(req, res, next) { ...@@ -14,18 +15,23 @@ router.get('/list/:page', function(req, res, next) {
14 else{ 15 else{
15 var page = req.params.page; 16 var page = req.params.page;
16 var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " + 17 var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " +
18 +<<<<<<< HEAD
17 "date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from userdb.board"; 19 "date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from userdb.board";
20 +=======
21 + "date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate,hit from board";
22 +>>>>>>> c29f2a5d1c3813d7d5c357acc015b4d40a6e701d
18 23
19 board.query(sql, function(err,rows) { 24 board.query(sql, function(err,rows) {
20 if (err) console.error("err : " + err); 25 if (err) console.error("err : " + err);
21 var id = req.user.ID; 26 var id = req.user.ID;
22 var nickname = req.user.nickname; 27 var nickname = req.user.nickname;
23 console.log(req.user.ID+'('+nickname+') 유저가 게시판을 보고있습니다.') 28 console.log(req.user.ID+'('+nickname+') 유저가 게시판을 보고있습니다.')
24 - res.render('list.ejs', {'ID':id, 'nickname': nickname, title: '게시판 리스트', rows: rows}) 29 + res.render('list.ejs', {'ID':id, 'nickname': nickname, title: '게시판 리스트', rows: rows, page:page, length:rows.length-1,page_num:10,pass:true})
25 }) 30 })
26 } 31 }
27 }); 32 });
28 33
34 +
29 router.get('/list', function(req,res,next){ 35 router.get('/list', function(req,res,next){
30 var id = req.user; 36 var id = req.user;
31 if(!id) res.sendFile(path.join(__dirname, "../../public/login.html")) 37 if(!id) res.sendFile(path.join(__dirname, "../../public/login.html"))
...@@ -102,4 +108,26 @@ router.post('/update', function(req,res,next){ ...@@ -102,4 +108,26 @@ router.post('/update', function(req,res,next){
102 }) 108 })
103 }) 109 })
104 110
111 +router.post('/delete', function(req,res,next){
112 + var idx = req.body.idx
113 + var passwd = req.body.passwd
114 + var datas = [idx,passwd]
115 +
116 + var sql = "delete from board where idx=? and passwd=?"
117 +
118 + board.query(sql,datas, function(err,result){
119 + if(err) console.error(err)
120 + if(result.affectedRows == 0){
121 + res.send("<script>alert('패스워드가 일치하지 않습니다.');history.back();</script>");
122 + }
123 + else
124 + {
125 + var id = req.user.ID;
126 + var nickname = req.user.nickname;
127 + console.log(req.user.ID+'('+nickname+') 유저가 '+idx+'번 게시글을 삭제했습니다.')
128 + res.redirect('/board/list/');
129 + }
130 + })
131 +})
132 +
105 module.exports = router; 133 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
34 </nav> 34 </nav>
35 <div class="container px-5 my-5"> 35 <div class="container px-5 my-5">
36 <h1><%= title %></h1> 36 <h1><%= title %></h1>
37 - <a href="/board/write">글쓰기</a>
38 <table border="1"> 37 <table border="1">
39 <tr> 38 <tr>
40 <td>번호</td> 39 <td>번호</td>
...@@ -45,9 +44,11 @@ ...@@ -45,9 +44,11 @@
45 <td>등록일</td> 44 <td>등록일</td>
46 </tr> 45 </tr>
47 <% 46 <%
48 - for(var i=0; i<rows.length; i++) 47 + for(var i = (page * page_num) - page_num; i < (page * page_num); i++) {
49 - { 48 + if(i > length){
50 - var data = rows[i]; 49 + i++;
50 + }else{
51 + var data = rows[i]
51 %> 52 %>
52 <tr> 53 <tr>
53 <td><%=data.idx%></td> 54 <td><%=data.idx%></td>
...@@ -57,8 +58,25 @@ ...@@ -57,8 +58,25 @@
57 <td><%=data.modidate%></td> 58 <td><%=data.modidate%></td>
58 <td><%=data.regdate%></td> 59 <td><%=data.regdate%></td>
59 </tr> 60 </tr>
60 - <%}%> 61 + <% }
62 + }
63 + %>
64 + <tr>
65 + <td colspan="6">
66 + <%
67 + for(var j = 0; j < rows.length / page_num; j++){
68 + %>
69 + [<a href="/board/list/<%= j + 1 %>"><%= j + 1 %></a>]
70 + <%
71 + }
72 + %>
73 + </td>
74 + </tr>
61 </table> 75 </table>
76 + <nav class="navbar">
77 + <a class="btn btn-outline-primary me-2" href="/board/write">글쓰기</a>
78 + </nav>
79 +
62 </div> 80 </div>
63 <!-- Footer--> 81 <!-- Footer-->
64 <footer class="footer bg-light"> 82 <footer class="footer bg-light">
......
...@@ -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,9 +70,12 @@ ...@@ -64,9 +70,12 @@
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>
69 - <a href="/board/list">목록</a> 75 + <button type="summit" onclick="return submit2(this.form);">글 삭제</button>
76 + <a href="/board/list">
77 + <input type="button" value="목록">
78 + </a>
70 </td> 79 </td>
71 </tr> 80 </tr>
72 </table> 81 </table>
......