Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김민규
/
rest_stop_list
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
min1925k@gmail.com
2022-06-04 13:35:52 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2771e47fdbe5604c5c780c179fc85b97e76989b9
2771e47f
1 parent
5148efb4
Post writer, logout debug
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
30 additions
and
58 deletions
app/database/post_schema.js
app/routes/login.js
app/routes/logout.js
app/routes/post.js
app/routes/showpost.js
app/views/post.ejs
app/views/postadd.ejs
app/views/showpost.ejs
app/database/post_schema.js
View file @
2771e47
...
...
@@ -6,10 +6,10 @@ var SchemaObj = {};
var
PostSchema
=
mongoose
.
Schema
({
title
:
{
type
:
String
,
trim
:
true
,
'default'
:
''
},
// 글 제목
contents
:
{
type
:
String
,
trim
:
true
,
'default'
:
''
},
// 글 내용
writer
:
{
type
:
mongoose
.
Schema
.
ObjectId
,
ref
:
'users
'
},
// 글쓴 사람
writer
:
{
type
:
String
,
'default'
:
'
'
},
// 글쓴 사람
comments
:
[{
// 댓글
contents
:
{
type
:
String
,
trim
:
true
,
'default'
:
''
},
// 댓글 내용
writer
:
{
type
:
mongoose
.
Schema
.
ObjectId
,
ref
:
'users
'
},
writer
:
{
type
:
String
,
'default'
:
'
'
},
created_at
:
{
type
:
Date
,
'default'
:
Date
.
now
}
}],
tags
:
{
type
:
[],
'default'
:
''
},
...
...
app/routes/login.js
View file @
2771e47
...
...
@@ -45,7 +45,9 @@ router.post('/process', function(req, res) {
}
else
{
// 조회된 레코드가 없는 경우 실패 응답 전송
res
.
render
(
'login.ejs'
);
res
.
render
(
'login.ejs'
,{
session
:
req
.
session
});
}
});
...
...
app/routes/logout.js
View file @
2771e47
...
...
@@ -7,8 +7,8 @@ var router = express.Router();
router
.
get
(
'/'
,
function
(
req
,
res
){
req
.
session
.
destroy
(
function
()
{
req
.
session
;
res
.
redirect
(
'/'
);
});
res
.
render
(
'index.ejs'
)
});
module
.
exports
=
router
\ No newline at end of file
...
...
app/routes/post.js
View file @
2771e47
...
...
@@ -82,46 +82,19 @@ router.get('/',function(req,res){
router
.
post
(
'/addpost'
,
function
(
req
,
res
)
{
var
paramTitle
=
req
.
body
.
title
||
req
.
query
.
title
;
var
paramContents
=
req
.
body
.
contents
||
req
.
query
.
contents
;
var
paramWriter
=
req
.
body
.
writer
||
req
.
query
.
writer
;
console
.
log
(
'요청 파라미터 : '
+
paramTitle
+
', '
+
paramContents
+
', '
+
paramWriter
);
var
paramWriter
=
req
.
session
.
sessId
;
var
database
=
req
.
app
.
get
(
'database'
);
// 데이터베이스 객체가 초기화된 경우
if
(
database
.
db
)
{
// 1. 아이디를 이용해 사용자 검색
database
.
UserModel
.
findById
(
paramWriter
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
'게시판 글 추가 중 에러 발생 : '
+
err
.
stack
);
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>게시판 글 추가 중 에러 발생</h2>'
);
res
.
write
(
'<p>'
+
err
.
stack
+
'</p>'
);
res
.
end
();
return
;
}
if
(
results
==
undefined
||
results
.
length
<
1
)
{
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>사용자 ['
+
paramWriter
+
']를 찾을 수 없습니다.</h2>'
);
res
.
end
();
return
;
}
var
userObjectId
=
results
[
0
].
_doc
.
_id
;
console
.
log
(
'사용자 ObjectId : '
+
paramWriter
+
' -> '
+
userObjectId
);
// save()로 저장
// PostModel 인스턴스 생성
var
post
=
new
database
.
PostModel
({
title
:
paramTitle
,
contents
:
paramContents
,
writer
:
userObjectId
writer
:
paramWriter
});
post
.
savePost
(
function
(
err
,
result
)
{
...
...
@@ -143,13 +116,6 @@ router.post('/addpost', function(req, res) {
return
res
.
redirect
(
'/post'
);
});
});
}
else
{
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>데이터베이스 연결 실패</h2>'
);
res
.
end
();
}
});
...
...
app/routes/showpost.js
View file @
2771e47
...
...
@@ -7,8 +7,6 @@ router.get('/:id',function(req,res){
// URL 파라미터로 전달됨
var
paramId
=
req
.
body
.
id
||
req
.
query
.
id
||
req
.
params
.
id
;
console
.
log
(
'요청 파라미터 : '
+
paramId
);
var
database
=
req
.
app
.
get
(
'database'
);
...
...
@@ -28,7 +26,6 @@ router.get('/:id',function(req,res){
}
if
(
results
)
{
console
.
dir
(
results
);
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
...
...
app/views/post.ejs
View file @
2771e47
...
...
@@ -4,9 +4,6 @@
<br>
<div class="ui raised segment">
<a class="ui blue ribbon label">게시판</a>
<div class="ui blue fluid card">
<div class="content">
<table border="1" width="800" align="center">
...
...
@@ -23,7 +20,7 @@
</tr>
<div class="ui very relaxed selection celled list">
<% var noStart = posts.length; for(var i=0; i < posts.length; i++){ var curTitle=posts[i]._doc.title;
var curNo=noStart - i; var createdDate = posts[i]._doc.created_at
;
%>
var curNo=noStart - i; var createdDate = posts[i]._doc.created_at
.toLocaleString(); curWriter = posts[i]._doc.writer;
%>
<tr align="center">
<td>
<%= curNo %>
...
...
@@ -32,7 +29,9 @@
<div class="fourteen wide column" onclick="javascript:window.location='/showpost/<%=posts[i]._id %>'">
<%= curTitle %>
</td>
<td>admin</td>
<td>
<%= curWriter %>
</td>
<td><%=createdDate%></td>
</tr>
<% } %>
...
...
app/views/postadd.ejs
View file @
2771e47
<%- include('./header.ejs') %>
<% if(session.sessId){ %>
<!-- Page Content-->
<div class="ui raised segment">
<a class="ui blue ribbon label">게시판</a>
...
...
@@ -25,14 +25,6 @@
<textarea id="contents" name="contents" rows="10" cols="80"></textarea>
</div>
<div class="two fields">
<div class="field">
<label>작성자</label>
<input type="text" name="writer" placeholder="작성자아이디 입력">
</div>
<div class="field"></div>
</div>
<input class="ui submit button" type="submit" value="추가" name="" />
<input class="ui button" type="button" value="취소" name="" onclick="javascript:history.back()" />
</form>
...
...
@@ -44,5 +36,21 @@
</div>
</main>
<% } else { %>
<!-- Page Content-->
<div class="ui blue fluid card">
<div class="content">
<form class="content ui form" method="post" action="/post/addpost">
<h4 class="ui dividing header">로그인이 필요합니다.</h4>
<br><br>
<a class="nav-link" href="/post">되돌아가기</a>
</div>
</div>
</div>
</main>
<% } %>
<!-- Footer-->
<%- include('./footer.ejs') %>
...
...
app/views/showpost.ejs
View file @
2771e47
...
...
@@ -11,7 +11,7 @@
<%
var curTitle = posts._doc.title;
var curContents = posts._doc.contents;
var curWriter =
"admin"
;
var curWriter =
posts._doc.writer
;
var entities = new Entities();
...
...
Please
register
or
login
to post a comment