Toggle navigation
Toggle navigation
This project
Loading...
Sign in
공태현
/
healthcare-with-webcam
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
공태현
2022-06-06 23:59:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ae6ab2380913abdac5d3526396ceac4834b2bcd4
ae6ab238
1 parent
7a0f63b3
Implement page move using LoginSession
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
18 deletions
server.js
views/mainPage/main.js
server.js
View file @
ae6ab23
...
...
@@ -12,10 +12,38 @@ app.set('port', port)
app
.
set
(
'view engine'
,
'ejs'
)
app
.
engine
(
'html'
,
ejs
.
renderFile
)
// model/user.js
const
{
User
}
=
require
(
'./model/User'
);
const
mongoose
=
require
(
'mongoose'
);
// db 연결을 위한 키 값 , 보안을 위해 최종 마스터 브런치에는 포함하지 않을 예정.
mongoose
.
connect
(
'mongodb+srv://kongtae:ksas9825!%40@squartusers.e2ddc.mongodb.net/?retryWrites=true&w=majority'
)
.
then
(()
=>
console
.
log
(
'MongoDB connect!'
))
.
catch
(
err
=>
console
.
log
(
err
))
// 로그인 세션 : 로그인 정보 유지.
const
express_session
=
require
(
'express-session'
)
app
.
use
(
express_session
({
secret
:
"@secret@number"
,
// 암호화 키
resave
:
false
,
saveUninitialized
:
false
,
store
:
require
(
'mongoose-session'
)(
mongoose
),
cookie
:
{
maxAge
:
60
*
60
*
24
}
}))
app
.
get
(
'/'
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
session
)
if
(
req
.
session
.
user
)
{
app
.
set
(
'views'
,
__dirname
+
'/views/squartPage'
)
res
.
render
(
'squart.html'
)
}
else
{
app
.
set
(
'views'
,
__dirname
+
'/views/mainPage'
)
res
.
render
(
'main.html'
)
}
})
...
...
@@ -25,6 +53,7 @@ app.get('/main.js', (req,res) => {
})
app
.
get
(
'/squart'
,
(
req
,
res
)
=>
{
app
.
set
(
'views'
,
__dirname
+
'/views/squartPage'
)
res
.
render
(
'squart.html'
)
})
...
...
@@ -33,25 +62,11 @@ app.listen(port, () => {
console
.
log
(
`Listening on
${
port
}
port`
);
})
// model/user.js
const
{
User
}
=
require
(
'./model/User'
);
const
mongoose
=
require
(
'mongoose'
);
// db 연결을 위한 키 값 , 보안을 위해 최종 마스터 브런치에는 포함하지 않을 예정.
mongoose
.
connect
(
'mongodb+srv://kongtae:ksas9825!%40@squartusers.e2ddc.mongodb.net/?retryWrites=true&w=majority'
)
.
then
(()
=>
console
.
log
(
'MongoDB connect!'
))
.
catch
(
err
=>
console
.
log
(
err
))
// 유저 등록 및 로그인 API
// 로그인 세션 : 로그인 정보 유지.
const
express_session
=
require
(
'express-session'
)
app
.
use
(
express_session
({
secret
:
"@secret@number"
,
// 암호화 키
resave
:
false
,
saveUninitialized
:
false
,
store
:
require
(
'mongoose-session'
)(
mongoose
),
cookie
:
{
maxAge
:
60
*
60
*
24
}
}))
// 등록 .
...
...
@@ -81,6 +96,8 @@ app.post('/api/users/login', (req ,res) => {
user_name
:
req
.
body
.
name
,
user_password
:
req
.
body
.
password
,
}
req
.
session
.
save
()
console
.
log
(
req
.
session
.
user
)
return
res
.
json
({
loginSuccess
:
true
,
...
...
@@ -127,6 +144,10 @@ app.get('/api/users/logout', (req,res) => {
})
// 세션 저장 확인
app
.
get
(
'/api/session'
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
session
.
user
)
...
...
views/mainPage/main.js
View file @
ae6ab23
...
...
@@ -5,9 +5,7 @@ function moveSquartPage()
location
.
href
=
"/squart"
;
}
const
movePage
=
document
.
getElementById
(
"moveSquart"
)
movePage
.
addEventListener
(
'click'
,
moveSquartPage
);
$
(
document
).
ready
(
function
(){
...
...
Please
register
or
login
to post a comment