Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최시원
/
Singer-Composer
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
unknown
2021-11-19 00:53:24 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
7a9678d7439eed31c18938f5a83825b20c254793
7a9678d7
2 parents
7263793a
c29f2a5d
myprof
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
12 deletions
readme.md
router/board/index.js
views/list.ejs
views/read.ejs
readme.md
View file @
7a9678d
...
...
@@ -33,7 +33,7 @@ CREATE TABLE `board` (
`passwd`
varchar(50) NOT NULL,
`hit`
int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (
`idx`
)
);
);
<br><br>
DB구조 - board에서 사용됨(
*
idx, name, title, content, regdate, modidate, passwd, hit)
<br>
*
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,
LF 오류시 git config --global core.autocrlf true 입력
<br><br>
최종 수정: 2021-11-1
8 20:03
<br>
최종 수정 내용: 메뉴바/하단 추가, 게시판에 기본 서식 추가, 로그인시에만 게시판 관련 경로에 접근가능하게 함, 사용자 로그 생성
최종 수정: 2021-11-1
9 12:19
<br>
최종 수정 내용: 메뉴바/하단 추가, 게시판에 기본 서식 추가, 로그인시에만 게시판 관련 경로에 접근가능하게 함, 사용자 로그 생성
<br>
수정 내용: 경로 지정 수정, 제목 추가, userDB, 회원가입에 nickname요소 추가, 세션에 ID + 닉네임 전달기능 추가, 게시판의 글쓰기 및 글 열람 기능 추가.
...
...
router/board/index.js
View file @
7a9678d
const
{
WSAECONNRESET
}
=
require
(
'constants'
);
const
e
=
require
(
'express'
);
var
express
=
require
(
'express'
);
const
{
connect
}
=
require
(
'http2'
);
...
...
@@ -14,18 +15,23 @@ router.get('/list/:page', function(req, res, next) {
else
{
var
page
=
req
.
params
.
page
;
var
sql
=
"select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, "
+
<<<<<<<
HEAD
"date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from userdb.board"
;
=======
"date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate,hit from board"
;
>>>>>>>
c29f2a5d1c3813d7d5c357acc015b4d40a6e701d
board
.
query
(
sql
,
function
(
err
,
rows
)
{
if
(
err
)
console
.
error
(
"err : "
+
err
);
var
id
=
req
.
user
.
ID
;
var
nickname
=
req
.
user
.
nickname
;
console
.
log
(
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 게시판을 보고있습니다.'
)
res
.
render
(
'list.ejs'
,
{
'ID'
:
id
,
'nickname'
:
nickname
,
title
:
'게시판 리스트'
,
rows
:
rows
})
res
.
render
(
'list.ejs'
,
{
'ID'
:
id
,
'nickname'
:
nickname
,
title
:
'게시판 리스트'
,
rows
:
rows
,
page
:
page
,
length
:
rows
.
length
-
1
,
page_num
:
10
,
pass
:
true
})
})
}
});
router
.
get
(
'/list'
,
function
(
req
,
res
,
next
){
var
id
=
req
.
user
;
if
(
!
id
)
res
.
sendFile
(
path
.
join
(
__dirname
,
"../../public/login.html"
))
...
...
@@ -102,4 +108,26 @@ router.post('/update', function(req,res,next){
})
})
router
.
post
(
'/delete'
,
function
(
req
,
res
,
next
){
var
idx
=
req
.
body
.
idx
var
passwd
=
req
.
body
.
passwd
var
datas
=
[
idx
,
passwd
]
var
sql
=
"delete from board where idx=? and passwd=?"
board
.
query
(
sql
,
datas
,
function
(
err
,
result
){
if
(
err
)
console
.
error
(
err
)
if
(
result
.
affectedRows
==
0
){
res
.
send
(
"<script>alert('패스워드가 일치하지 않습니다.');history.back();</script>"
);
}
else
{
var
id
=
req
.
user
.
ID
;
var
nickname
=
req
.
user
.
nickname
;
console
.
log
(
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 '
+
idx
+
'번 게시글을 삭제했습니다.'
)
res
.
redirect
(
'/board/list/'
);
}
})
})
module
.
exports
=
router
;
\ No newline at end of file
...
...
views/list.ejs
View file @
7a9678d
...
...
@@ -34,7 +34,6 @@
</nav>
<div
class=
"container px-5 my-5"
>
<h1>
<
%= title %>
</h1>
<a
href=
"/board/write"
>
글쓰기
</a>
<table
border=
"1"
>
<tr>
<td>
번호
</td>
...
...
@@ -45,9 +44,11 @@
<td>
등록일
</td>
</tr>
<
%
for(var i=0; i
<rows
.
length
;
i
++)
{
var
data =
rows[i];
for(var i = (page * page_num) - page_num; i
<
(page * page_num); i++) {
if(i > length){
i++;
}else{
var data = rows[i]
%>
<tr>
<td>
<
%=data.idx%>
</td>
...
...
@@ -57,8 +58,25 @@
<td>
<
%=data.modidate%>
</td>
<td>
<
%=data.regdate%>
</td>
</tr>
<
%}%>
<
% }
}
%>
<tr>
<td
colspan=
"6"
>
<
%
for(var j = 0; j
< rows
.
length
/
page_num
;
j
++){
%
>
[
<a
href=
"/board/list/<%= j + 1 %>"
>
<
%= j + 1 %>
</a>
]
<
%
}
%>
</td>
</tr>
</table>
<nav
class=
"navbar"
>
<a
class=
"btn btn-outline-primary me-2"
href=
"/board/write"
>
글쓰기
</a>
</nav>
</div>
<!-- Footer-->
<footer
class=
"footer bg-light"
>
...
...
views/read.ejs
View file @
7a9678d
...
...
@@ -31,7 +31,13 @@
</nav>
<div
class=
"container px-5 my-5"
>
<h1>
<
%= title %>
</h1>
<script>
function
submit2
(
frm
){
frm
.
action
=
"/board/delete"
;
frm
.
submit
();
return
true
;
}
</script>
<form
action=
"/board/update"
method=
"post"
>
<table
border=
"1"
>
<input
type=
"hidden"
name=
"idx"
value=
"<%=row.idx%>"
/>
...
...
@@ -64,9 +70,12 @@
<td>
<
%=row.hit%>
</td>
</tr>
<tr>
<td
colspan=
"
2
"
>
<td
colspan=
"
3
"
>
<button
type=
"submit"
>
글 수정
</button>
<a
href=
"/board/list"
>
목록
</a>
<button
type=
"summit"
onclick=
"return submit2(this.form);"
>
글 삭제
</button>
<a
href=
"/board/list"
>
<input
type=
"button"
value=
"목록"
>
</a>
</td>
</tr>
</table>
...
...
Please
register
or
login
to post a comment