Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김건희
/
OSSW_Weather_Briefing
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
Seokjin
2022-05-14 02:22:58 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bcee7e7c9b5991b6db50e7e4331ddd428f427042
bcee7e7c
1 parent
24a814c0
[update]login/logout
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
weather_briefing/server/server.js
weather_briefing/server/server.js
0 → 100644
View file @
bcee7e7
const
express
=
require
(
'express'
);
const
mongoose
=
require
(
'mongoose'
);
mongoose
.
connect
(
'mongo://localhost:27017/testDB'
);
const
app
=
express
();
let
logid
=
{
name
:
null
,
id
:
null
,
password
:
null
,
sex
:
null
,
log
:
false
};
let
db
=
mongoose
.
connection
;
// 몽고디비를 어떻게 사용해야하는지를 정확히 몰라서 우선 이렇게 해보겠습니다.
db
.
on
(
'error'
,
function
(){
console
.
log
(
'Connection Failed!'
);
});
db
.
once
(
'open'
,
function
(){
console
.
log
(
'Connected!'
);
});
let
user
=
mongoose
.
Schema
({
name
:
String
,
id
:
String
,
password
:
String
,
sex
:
Number
});
let
User
=
mongoose
.
model
(
'users'
,
UserSchema
);
app
.
post
(
'/signup'
,(
req
,
res
)
=>
{
let
newUser
=
new
User
(
req
.
body
);
newUser
.
save
(
function
(
error
,
data
){
if
(
error
){
res
.
send
(
'error'
);
}
else
{
res
.
send
(
'saved!'
);
}
});
//logid에다가 몽고디비에서 가져온 데이터를 넣고 로그인 된 상태로 만들고 싶음
});
app
.
post
(
'/login'
,(
req
,
res
)
=>
{
User
.
findOne
({
id
:
req
.
body
.
id
,
password
:
req
.
body
.
password
},(
err
,
user
)
=>
{
if
(
err
){
res
.
send
(
'아이디와 비밀번호를 다시 확인해주십시오.'
);
}
else
{
res
.
send
(
'로그인 되었습니다.'
);
}
});
});
app
.
post
(
'/logout'
,(
req
,
res
)
=>
{
logid
.
id
=
null
;
res
.
send
(
'로그아웃 되었습니다.'
);
});
\ No newline at end of file
Please
register
or
login
to post a comment