Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오인제
/
Tunnel
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
고병후
2021-12-08 00:27:16 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b4fa2199392243b18202fe1f878611ab4b2a5850
b4fa2199
1 parent
cd1a75f0
Make session
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
15 deletions
tunnel_BE/server/routes/login.js
tunnel_BE/server/routes/main.js
tunnel_BE/server/routes/register.js
tunnel_BE/server/server.js
tunnel_BE/server/routes/login.js
View file @
b4fa219
...
...
@@ -2,19 +2,39 @@ const express = require("express");
const
bodyParser
=
require
(
"body-parser"
);
const
router
=
express
.
Router
();
const
{
User
}
=
require
(
'../models'
);
router
.
get
(
'/'
,(
req
,
res
)
=>
{
//res.send('로그인 페이지');
});
//라우트 매개변수사용
//후방 위치 요구
/*
router.get("/:id",(req,res)=>{
console.log(req.body);
//res.json({id:"oss_hi"});
//로그인 시도
router
.
post
(
'/'
,(
req
,
res
)
=>
{
User
.
findOne
({
where
:{
name
:
req
.
body
.
Id
}
})
.
then
((
result
)
=>
{
//id와 일치하는 정보가 없는경우
if
(
result
===
null
||
result
===
undefined
){
console
.
log
(
"일치하는 id가 없습니다."
)
res
.
sendStatus
(
401
);
}
//비밀번호 불일치
else
if
(
result
.
dataValues
.
pw
!=
req
.
body
.
Password
){
console
.
log
(
"일치하는 pw가 없습니다."
)
res
.
sendStatus
(
401
);
}
else
if
(
result
.
dataValues
.
pw
==
req
.
body
.
Password
){
req
.
session
.
id
=
result
.
dataValues
.
id
;
req
.
session
.
name
=
result
.
dataValues
.
name
;
req
.
session
.
personality
=
result
.
dataValues
.
personality
;
req
.
session
.
status
=
result
.
dataValues
.
status
;
console
.
log
(
"Login"
);
res
.
sendStatus
(
200
);
}
})
});
*/
...
...
tunnel_BE/server/routes/main.js
0 → 100644
View file @
b4fa219
const
express
=
require
(
"express"
);
const
bodyParser
=
require
(
"body-parser"
);
const
router
=
express
.
Router
();
const
{
User
}
=
require
(
'../models'
);
router
.
get
(
'/'
,(
req
,
res
)
=>
{
//메인페이지
//테스트 코드
console
.
log
(
req
.
session
.
id
);
res
.
send
(
req
.
session
.
name
);
});
module
.
exports
=
router
;
\ No newline at end of file
tunnel_BE/server/routes/register.js
View file @
b4fa219
...
...
@@ -10,15 +10,29 @@ router.get('/',(req,res)=>{
res
.
send
(
'회원가입 페이지'
);
});
//회원가입
router
.
post
(
'/'
,(
req
,
res
)
=>
{
User
.
create
({
name
:
req
.
body
.
Id
,
pw
:
req
.
body
.
Password
,
personality
:
req
.
body
.
Personality
,
status
:
false
User
.
findOne
({
where
:{
name
:
req
.
body
.
Id
}
})
console
.
log
(
req
.
body
);
return
res
.
sendStatus
(
200
);
.
then
((
result
)
=>
{
//id가 중복되지 않는 경우
if
(
result
===
null
||
result
===
undefined
){
User
.
create
({
name
:
req
.
body
.
Id
,
pw
:
req
.
body
.
Password
,
personality
:
req
.
body
.
Personality
,
status
:
false
})
console
.
log
(
req
.
body
);
return
res
.
sendStatus
(
200
);
}
//id중복
else
{
console
.
log
(
"중복된 id"
);
return
res
.
sendStatus
(
401
);
}
})
});
//라우트 매개변수사용
...
...
tunnel_BE/server/server.js
View file @
b4fa219
...
...
@@ -13,6 +13,7 @@ dotenv.config();
const
indexRouter
=
require
(
'./routes/index.js'
);
const
loginRouter
=
require
(
'./routes/login.js'
);
const
registerRouter
=
require
(
'./routes/register.js'
);
const
mainRouter
=
require
(
'./routes/main.js'
);
const
app
=
express
();
app
.
set
(
'port'
,
process
.
env
.
PORT
||
3001
);
...
...
@@ -47,6 +48,7 @@ app.use(session({
//라우팅
app
.
use
(
'/api/register'
,
registerRouter
);
// 회원가입 페이지
app
.
use
(
'/api/login'
,
loginRouter
);
//로그인 페이지
app
.
use
(
'/api/main'
,
mainRouter
);
//메인페이지
//에러처리 미들웨어
...
...
Please
register
or
login
to post a comment