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
김건희
2022-05-23 17:01:02 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1a2aaae2fea792111e6facca536cf751aecc7660
1a2aaae2
1 parent
d817e379
[Update] Register Files
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
19 deletions
weather_briefing/package-lock.json
weather_briefing/package.json
weather_briefing/server/server.js
weather_briefing/package-lock.json
View file @
1a2aaae
This diff is collapsed. Click to expand it.
weather_briefing/package.json
View file @
1a2aaae
...
...
@@ -9,6 +9,7 @@
"cors"
:
"^2.8.5"
,
"express"
:
"^4.18.1"
,
"http-proxy-middleware"
:
"^2.0.6"
,
"mongoose"
:
"^6.3.4"
,
"nodemon"
:
"^2.0.16"
,
"react"
:
"^18.1.0"
,
"react-dom"
:
"^18.1.0"
,
...
...
@@ -19,7 +20,8 @@
"start"
:
"react-scripts start"
,
"build"
:
"react-scripts build"
,
"test"
:
"react-scripts test"
,
"eject"
:
"react-scripts eject"
"eject"
:
"react-scripts eject"
,
"server"
:
"node server.js"
},
"eslintConfig"
:
{
"extends"
:
[
...
...
weather_briefing/server/server.js
View file @
1a2aaae
...
...
@@ -2,9 +2,14 @@ let express = require('express');
let
bodyParser
=
require
(
'body-parser'
);
let
mongoose
=
require
(
'mongoose'
);
let
cors
=
require
(
'cors'
);
let
app
=
express
();
app
.
use
(
cors
());
let
logid
=
null
;
const
uri
=
'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'
;
//const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
const
uri
=
'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority'
;
let
db
=
mongoose
.
connect
(
uri
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
err
.
message
);
...
...
@@ -16,8 +21,8 @@ let db = mongoose.connect(uri, (err) => {
var
UserSchema
=
new
mongoose
.
Schema
({
name
:
String
,
id
:
String
,
password
:
String
,
gender
:
Number
password
:
String
,
gender
:
String
});
var
Users
=
mongoose
.
model
(
'users'
,
UserSchema
);
...
...
@@ -25,25 +30,33 @@ var Users = mongoose.model('users', UserSchema);
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
limit
:
'1gb'
,
extended
:
false
}));
app
.
post
(
'/signup'
,
(
req
,
res
)
=>
{
Users
.
findOne
({
id
:
req
.
body
.
id
,
password
:
req
.
body
.
password
},
(
err
,
user
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
message
:
'에러가 발생하였습니다.'
});
else
if
(
user
){
res
.
send
(
'이미 존재하는 사용자입니다.'
);
}
else
{
var
new_user
=
new
Users
(
req
.
body
);
app
.
post
(
'/api/register'
,
(
req
,
res
)
=>
{
const
new_user
=
new
Users
(
req
.
body
);
new_user
.
save
((
err
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
message
:
'회원가입에 실패하였습니다.'
});
else
return
res
.
status
(
200
).
json
({
message
:
'회원가입이 완료되었습니다.'
,
data
:
new_user
});
});
new_user
.
save
((
err
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
registerSuccess
:
false
});
else
return
res
.
status
(
200
).
json
({
registerSuccess
:
true
});
})
/*Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else if (user){
res.json({ registerSuccess: '0'});
}
});
else{
const new_user = new Users(req.body);
new_user.save((err) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else return res.status(200).json({ registerSuccess: '1'});
});
}
});*/
});
app
.
post
(
'/
sign
in'
,
(
req
,
res
)
=>
{
app
.
post
(
'/
api/log
in'
,
(
req
,
res
)
=>
{
Users
.
findOne
({
id
:
req
.
body
.
id
,
password
:
req
.
body
.
password
},
(
err
,
user
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
message
:
'에러가 발생하였습니다.'
});
else
if
(
user
){
...
...
@@ -53,8 +66,10 @@ app.post('/signin', (req, res) => {
else
return
res
.
status
(
404
).
json
({
message
:
'아이디와 비밀번호를 다시 확인해주세요.'
});
});
});
app
.
post
(
'/logout'
,(
req
,
res
)
=>
{
app
.
post
(
'/api/logout'
,(
req
,
res
)
=>
{
logid
=
null
;
res
.
send
(
'로그아웃 되었습니다.'
);
});
app
.
listen
(
4000
,
()
=>
console
.
log
(
'Server On 4000'
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment