Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
656540dc
Commit
656540dc
authored
Jul 26, 2021
by
KangMin An
Browse files
Update: User model. Auth Process.
parent
83f2c063
Changes
4
Show whitespace changes
Inline
Side-by-side
server/src/controllers/dataController.js
View file @
656540dc
import
fetch
from
"
node-fetch
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
db
from
"
../db/index
"
;
import
dotenv
from
"
dotenv
"
;
import
fetch
from
"
node-fetch
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
dotenv
.
config
();
...
...
@@ -34,10 +35,10 @@ const handleOutData = async (locCode, date, lat, lng) => {
};
// 내부 수집기로 부터 들어온 정보 처리
const
handleInData
=
async
(
id
,
date
,
temp
,
humi
,
lights
)
=>
{
const
handleInData
=
async
(
email
,
date
,
temp
,
humi
,
lights
)
=>
{
db
.
Weather_in
.
create
(
{
host
:
id
,
host
:
email
,
collected_at
:
date
,
temp
:
temp
,
humi
:
humi
,
...
...
@@ -59,15 +60,15 @@ export const getDataInput = (req, res) => {
}
=
req
;
console
.
log
(
locCode
,
date
,
lat
,
lng
);
//
handleOutData(locCode, date, lat, lng);
handleOutData
(
locCode
,
date
,
lat
,
lng
);
}
else
{
// 내부 데이터 수집기 동작
const
{
query
:
{
id
,
locCode
,
date
,
temp
,
humi
,
lights
},
query
:
{
id
,
date
,
temp
,
humi
,
lights
},
}
=
req
;
console
.
log
(
id
,
locCode
,
date
,
temp
,
humi
,
lights
);
//
handleInData(id, date, temp, humi, lights);
console
.
log
(
id
,
date
,
temp
,
humi
,
lights
);
handleInData
(
id
,
date
,
temp
,
humi
,
lights
);
}
res
.
status
(
statusCode
.
ok
).
send
(
serverMSG
.
server_ok
);
...
...
@@ -80,19 +81,22 @@ export const getDataInput = (req, res) => {
// 사용자의 데이터 가져오기 및 예측 값 전송
export
const
getUserWeatherData
=
(
req
,
res
)
=>
{
const
{
params
:
{
email
},
cookies
:
{
acs_token
},
}
=
req
;
/* 사용자 email에 따른 사용자 날씨 데이터 가져오기 */
const
decoded
=
jwt
.
decode
(
acs_token
);
const
result
=
db
.
Weather_in
.
findAll
({
where
:
{
host
:
decoded
.
email
},
logging
:
false
,
});
res
.
status
(
statusCode
.
ok
).
send
(
serverMSG
.
server_ok
);
res
.
status
(
statusCode
.
ok
).
json
({
msg
:
serverMSG
.
server_ok
,
content
:
result
}
);
};
// 지역 코드 요청 처리
export
const
getLocCode
=
async
(
req
,
res
)
=>
{
/* 통합 지역 코드 및 이름 json으로 생성 및 전송 */
let
locCodes
=
[];
const
does
=
await
db
.
Doe
.
findAll
({
logging
:
false
});
const
sggs
=
await
db
.
Sgg
.
findAll
({
logging
:
false
});
const
emds
=
await
db
.
Emd
.
findAll
({
logging
:
false
});
...
...
server/src/controllers/userController.js
View file @
656540dc
...
...
@@ -136,22 +136,12 @@ export const getConfirm = async (req, res) => {
};
const
accessT
=
jwt
.
sign
(
payload
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
,
{
expiresIn
:
"
6h
"
,
issuer
:
"
eue.com
"
,
subject
:
"
userInfo
"
,
});
const
refreshT
=
jwt
.
sign
(
payload
,
process
.
env
.
AUTH_REFRESH_SECRETKEY
,
{
expiresIn
:
"
14d
"
,
issuer
:
"
eue.com
"
,
subject
:
"
userInfo
"
,
});
res
.
status
(
statusCode
.
ok
)
.
cookie
(
"
access_token
"
,
accessT
)
.
cookie
(
"
refresh_token
"
,
refreshT
)
.
redirect
(
"
/api
"
);
res
.
status
(
statusCode
.
ok
).
cookie
(
"
acs_token
"
,
accessT
).
redirect
(
"
/api
"
);
}
catch
(
err
)
{
res
.
status
(
statusCode
.
err
)
...
...
server/src/middlewares.js
View file @
656540dc
import
routes
from
"
./routes
"
;
import
jwt
from
"
jsonwebtoken
"
;
/*
# localmiddleware
...
...
@@ -12,8 +13,18 @@ export const localmiddleware = (req, res, next) => {
/*
# onlyPrivate
- 인증된 사용자만 사용할 수 있는 데이터에 접근하기 위한 중간 과정.
- Front-end 개발과 함께 진행 예정
*/
export
const
onlyPrivate
=
(
req
,
res
,
next
)
=>
{
const
{
cookies
:
{
acs_Token
},
}
=
req
;
try
{
const
acs_decode
=
jwt
.
verify
(
acs_Token
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
);
console
.
log
(
`User[
${
acs_decode
.
email
}
] Data Access.`
);
next
();
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
redirect
(
"
/api/login
"
);
}
};
server/src/models/user.js
View file @
656540dc
...
...
@@ -16,13 +16,21 @@ export class User extends Model {
email
:
{
type
:
DataTypes
.
STRING
(
320
),
allowNull
:
false
,
primaryKey
:
true
,
unique
:
true
,
},
nick_name
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
unique
:
true
,
},
using_oauth
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
},
using_aircon
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
},
},
{
sequelize
,
...
...
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