Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
travel
Commits
9fe5e544
Commit
9fe5e544
authored
Jul 11, 2022
by
Lee Soobeom
Browse files
Merge branch 'sb6' into sb7
parents
b8dcc783
3b01ee29
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/controllers/auth.controller.ts
View file @
9fe5e544
...
@@ -35,7 +35,7 @@ export const login = asyncWrap(async (req, res) => {
...
@@ -35,7 +35,7 @@ export const login = asyncWrap(async (req, res) => {
maxAge
:
cookieConfig
.
maxAge
,
// 이 기간 내에서만 유효
maxAge
:
cookieConfig
.
maxAge
,
// 이 기간 내에서만 유효
path
:
"
/
"
,
//어떠한 경로에 관해서만 쓴다. 지금은 전부에 쓴다.
path
:
"
/
"
,
//어떠한 경로에 관해서만 쓴다. 지금은 전부에 쓴다.
httpOnly
:
envConfig
.
mode
===
"
production
"
,
//false면 브라우저에서 쿠키를 조작, true면 조작할 수 없다.
httpOnly
:
envConfig
.
mode
===
"
production
"
,
//false면 브라우저에서 쿠키를 조작, true면 조작할 수 없다.
secure
:
envConfig
.
mode
===
"
production
"
,
//true
면 https를 통해서만 쿠키 전달, false면
secure
:
envConfig
.
mode
===
"
production
"
,
//
true면 https를 통해서만 쿠키 전달, false면
불가능
});
});
// 5) 사용자 반환
// 5) 사용자 반환
res
.
json
({
res
.
json
({
...
@@ -89,6 +89,7 @@ export const signup = asyncWrap(async (req, res) => {
...
@@ -89,6 +89,7 @@ export const signup = asyncWrap(async (req, res) => {
// 3) 비밀번호 암호화는 useDb.createUser에서 처리
// 3) 비밀번호 암호화는 useDb.createUser에서 처리
// 4) 새로운 사용자 만들기
// 4) 새로운 사용자 만들기
const
newUser
=
await
userDb
.
createUser
({
const
newUser
=
await
userDb
.
createUser
({
name
,
email
,
email
,
password
,
password
,
});
});
...
...
src/controllers/post.controller.ts
View file @
9fe5e544
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
import
equals
from
"
validator/lib/equals
"
;
import
{
requireLogin
}
from
"
./auth.controller
"
;
import
{
asyncWrap
}
from
"
../helpers
"
;
import
{
asyncWrap
}
from
"
../helpers
"
;
import
{
postDb
}
from
"
../db
"
;
import
{
postDb
}
from
"
../db
"
;
...
@@ -9,6 +10,8 @@ export const posting = asyncWrap(async (req, res) => {
...
@@ -9,6 +10,8 @@ export const posting = asyncWrap(async (req, res) => {
console
.
log
(
"
body
"
,
req
.
body
);
console
.
log
(
"
body
"
,
req
.
body
);
// 0) 로그인 했는지 확인 requireLogin
// 1) title 빈 문자열인지 확인
// 1) title 빈 문자열인지 확인
if
(
!
isLength
(
title
??
""
,
{
min
:
1
}))
{
if
(
!
isLength
(
title
??
""
,
{
min
:
1
}))
{
return
res
.
status
(
422
).
send
(
"
제목을 한 글자 이상 입력해주세요
"
);
return
res
.
status
(
422
).
send
(
"
제목을 한 글자 이상 입력해주세요
"
);
...
@@ -29,9 +32,8 @@ export const posting = asyncWrap(async (req, res) => {
...
@@ -29,9 +32,8 @@ export const posting = asyncWrap(async (req, res) => {
return
res
.
status
(
422
).
send
(
"
도시를 선택해 주세요
"
);
return
res
.
status
(
422
).
send
(
"
도시를 선택해 주세요
"
);
}
}
// 5) username
확인 필요 없음
// 5) username
ref: cookie.token._id -> collection users, "User"-> name
// 6)
const
newPosting
=
await
postDb
.
createPosting
({
const
newPosting
=
await
postDb
.
createPosting
({
title
,
title
,
text
,
text
,
...
...
src/db/post.db.ts
View file @
9fe5e544
...
@@ -9,7 +9,7 @@ export const createPosting = async (posting: PostingType) => {
...
@@ -9,7 +9,7 @@ export const createPosting = async (posting: PostingType) => {
city
:
posting
.
city
,
city
:
posting
.
city
,
username
:
posting
.
username
,
username
:
posting
.
username
,
date
:
posting
.
date
,
date
:
posting
.
date
,
counts
:
posting
.
counts
,
counts
:
0
,
});
});
return
newPosting
;
return
newPosting
;
};
};
src/db/user.db.ts
View file @
9fe5e544
...
@@ -4,7 +4,11 @@ import { IUser, User } from "../models";
...
@@ -4,7 +4,11 @@ import { IUser, User } from "../models";
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
// 비밀번호 암호화
// 비밀번호 암호화
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
newUser
=
await
User
.
create
({
email
:
user
.
email
,
password
:
hash
});
const
newUser
=
await
User
.
create
({
email
:
user
.
email
,
password
:
hash
,
name
:
user
.
name
,
});
return
newUser
;
return
newUser
;
};
};
...
...
src/models/posting.model.ts
View file @
9fe5e544
...
@@ -27,6 +27,14 @@ const postingSchema = new Schema<PostingType>({
...
@@ -27,6 +27,14 @@ const postingSchema = new Schema<PostingType>({
},
},
username
:
{
username
:
{
type
:
String
,
type
:
String
,
// username: travelreport.users.findOne({id: cookie.token._id(Schema.Tpyes.ObjectId)}).name,
},
date
:
{
type
:
Date
,
default
:
Date
.
now
,
},
counts
:
{
type
:
Number
,
},
},
date
:
{
date
:
{
type
:
Date
,
type
:
Date
,
...
...
src/routes/index.ts
View file @
9fe5e544
...
@@ -8,6 +8,5 @@ const router = express.Router();
...
@@ -8,6 +8,5 @@ const router = express.Router();
router
.
use
(
"
/users
"
,
userRouter
);
router
.
use
(
"
/users
"
,
userRouter
);
router
.
use
(
"
/auth
"
,
authRouter
);
router
.
use
(
"
/auth
"
,
authRouter
);
router
.
use
(
"
/posts
"
,
postRouter
);
router
.
use
(
"
/posts
"
,
postRouter
);
//posting함수 -> mongodb에 posts json형식으로 저장
export
default
router
;
export
default
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment