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
Mukho
2021-11-26 16:22:43 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
31570ce8cf1edf3810f8315365806b8831adc751
31570ce8
2 parents
8b0b097e
f2c60f61
Merge branch 'master' of
http://khuhub.khu.ac.kr/2017104034/Singer-Composer
into master
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
3 deletions
readme.md
router/board/index.js
views/read.ejs
readme.md
View file @
31570ce
...
...
@@ -46,6 +46,15 @@ create table board(
hit int not null,
ID varchar(20) not null
)engine=innodb;
create table comment(
idx int auto_increment primary key,
ID varchar(20) not null,
nickname varchar(50) not null,
comment mediumtext not null,
bulletin_id int not null,
foreign key (bulletin_id) references board(idx) on delete cascade
)engine=innodb;
```
---
...
...
@@ -61,7 +70,7 @@ create table board(
>UPDATE board SET idx = @COUNT:=@COUNT+1;
---
### 최종 수정: 2021-11-2
5 20:24
<br>
### 최종 수정: 2021-11-2
6 04:42
<br>
### 수정 내용:
0.
채팅 중 서버 재시작시 기존 참여자들 리셋시키기 이슈
1.
채팅 구현
...
...
@@ -72,3 +81,4 @@ create table board(
6.
채팅(socket) 사용 중 서버 재시작 시 서버 오류 해결
7.
코드 다듬음
8.
버그 수정
9.
댓글 등록, 열람 기능 구현. 삭제 기능 불완전함(달린 댓글이 1개일 때만 삭제기능 동작)
\ No newline at end of file
...
...
router/board/index.js
View file @
31570ce
...
...
@@ -124,12 +124,76 @@ router.get('/read/:idx', function(req,res,next){
if
(
err
)
console
.
error
(
err
)
})
var
sql_comment
=
"select idx, nickname, comment from comment where bulletin_id =?"
board
.
query
(
sql_comment
,
[
idx
],
function
(
err
,
comment
){
if
(
err
)
console
.
error
(
"err : "
+
err
);
res
.
render
(
'read.ejs'
,
{
'ID'
:
id
,
'nickname'
:
nickname
,
title
:
"글 상세"
,
row
:
row
[
0
],
comment
:
comment
,
comment_length
:
comment
.
length
,
usernick
:
req
.
user
.
nickname
})
})
console
.
log
(
logString
+
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 '
+
idx
+
'번 게시글을 보고있습니다.('
+
ip
+
')'
)
res
.
render
(
'read.ejs'
,
{
'ID'
:
id
,
'nickname'
:
nickname
,
title
:
"글 상세"
,
row
:
row
[
0
]})
}
})
})
router
.
post
(
'/read/commentwrite'
,
function
(
req
,
res
,
next
){
var
ip
=
requestIp
.
getClientIp
(
req
);
var
idx
=
req
.
body
.
idx
;
var
nickname
=
req
.
user
.
nickname
// var name = req.body.name
var
comment
=
req
.
body
.
comment
var
ID
=
req
.
user
.
ID
var
datas
=
[
ID
,
nickname
,
comment
,
idx
]
var
sql
=
"insert into comment(ID, nickname, comment, bulletin_id) values(?, ?, ?, ?)"
board
.
query
(
sql
,
datas
,
function
(
err
,
row
){
if
(
err
)
console
.
error
(
"err : "
+
err
);
})
res
.
redirect
(
'/board/read/'
+
idx
);
})
router
.
post
(
'/read/commentdelete'
,
function
(
req
,
res
,
next
){
var
ip
=
requestIp
.
getClientIp
(
req
);
var
idx
=
req
.
body
.
idxcomment
;
var
idxbulletin
=
req
.
body
.
idx
;
var
ID
=
req
.
user
.
ID
;
var
datas
=
[
ID
,
idx
]
var
sql
=
"delete from comment where ID =? and idx=?"
board
.
query
(
sql
,
datas
,
function
(
err
,
result
){
if
(
err
)
console
.
error
(
err
)
// 삭제를 요청한 사용자가 작성자가 아닌 경우
if
(
result
.
affectedRows
==
0
){
// 운영자세요?
var
sql_
=
'select type from userdb where ID="'
+
ID
+
'"'
;
board
.
query
(
sql_
,
function
(
err_
,
result_
){
if
(
err_
)
console
.
error
(
err_
)
if
(
result_
[
0
].
type
==
"운영자"
){
// 작성자는 아니나 유저 타입이 운영자인 경우
var
sqlAdmin
=
'delete from comment where idx="'
+
idx
+
'"'
;
board
.
query
(
sqlAdmin
,
function
(
err__
,
result__
){
if
(
err__
)
console
.
error
(
err__
)
var
nickname
=
req
.
user
.
nickname
;
res
.
send
(
"<script>alert('댓글이 운영자에 의해 삭제되었습니다.');window.location.href='/board/read/"
+
idxbulletin
+
"';</script>"
);
console
.
log
(
logString
+
"[Admin] "
+
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 '
+
idx
+
'번 댓글을 삭제했습니다.('
+
ip
+
')'
)
})
}
else
{
// 작성자도, 운영자도 아니면
var
nickname
=
req
.
user
.
nickname
;
console
.
log
(
logString
+
req
.
user
.
ID
+
'('
+
nickname
+
') 유저의 '
+
idx
+
'번 댓글 삭제를 거부했습니다.(권한없음 // '
+
ip
+
')'
)
res
.
send
(
"<script>alert('댓글 작성자가 아닙니다');history.back();</script>"
);
}
})
}
else
{
// 작성자인 경우
var
id
=
req
.
user
.
ID
;
var
nickname
=
req
.
user
.
nickname
;
res
.
send
(
"<script>alert('댓글이 삭제되었습니다.');window.location.href='/board/read/"
+
idxbulletin
+
"';</script>"
);
console
.
log
(
logString
+
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 '
+
idx
+
'번 댓글을 삭제했습니다.('
+
ip
+
')'
)
}
})
})
router
.
post
(
'/update'
,
function
(
req
,
res
,
next
){
var
ip
=
requestIp
.
getClientIp
(
req
);
var
ID
=
req
.
user
.
ID
;
...
...
@@ -163,7 +227,6 @@ router.post('/delete', function(req,res,next){
var
sql
=
"delete from board where idx=? and ID=?"
board
.
query
(
sql
,
datas
,
function
(
err
,
result
){
if
(
err
)
console
.
error
(
err
)
// 삭제를 요청한 사용자가 작성자가 아닌 경우
if
(
result
.
affectedRows
==
0
){
// 운영자세요?
...
...
views/read.ejs
View file @
31570ce
...
...
@@ -77,6 +77,51 @@
</table>
</form>
</div>
<div
class=
"container px-5 my-5"
>
<h1>
댓글
</h1>
<script>
function
submit3
(
frm
){
frm
.
action
=
"/board/read/commentdelete"
;
frm
.
submit
();
return
true
;
}
function
deleteit
(
buttonID
){
}
</script>
<form
action=
"/board/read/commentwrite"
method=
"post"
>
<table
border=
"1"
>
<input
type=
"hidden"
name=
"idx"
value=
"<%=row.idx%>"
/>
<tr>
<td>
닉네임
</td>
<td>
댓글
</td>
</tr>
<
%
for(var i=0; i
<comment
_length
;
i
++){
var
data =
comment[i]
%
>
<tr>
<td>
<
%=data.nickname%>
</td>
<td>
<
%=data.comment%>
</td>
<td>
<input
type=
"hidden"
name=
"idxcomment"
value=
"<%=data.idx%>"
/>
<button
type=
"button"
id=
"<%=data.idx%>"
onclick=
"return submit3(this.form);"
>
댓글 삭제
</button>
</td>
</tr>
<
%
}
%>
<tr>
<td>
<
%=usernick%>
</td>
<td><textarea
name=
"comment"
id=
"comment"
cols=
"30"
rows=
"2"
required
></textarea></td>
<td
colspan=
"2"
>
<button
type=
"submit"
>
댓글 쓰기
</button>
</td>
</tr>
</table>
</form>
</div>
<!-- Footer-->
<footer
class=
"footer bg-light"
>
<div
class=
"container"
>
...
...
Please
register
or
login
to post a comment