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
83f2c063
Commit
83f2c063
authored
Jul 23, 2021
by
KangMin An
Browse files
Update : User Autthorization Token Setting.
parent
787d8e4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/src/controllers/userController.js
View file @
83f2c063
...
@@ -60,12 +60,12 @@ export const postSignup = async (req, res) => {
...
@@ -60,12 +60,12 @@ export const postSignup = async (req, res) => {
body
:
{
email
,
nick_name
},
body
:
{
email
,
nick_name
},
}
=
req
;
}
=
req
;
const
result
=
await
db
.
User
.
find
One
({
const
result
=
await
db
.
User
.
find
All
({
where
:
{
email
:
email
},
where
:
{
email
:
email
},
logging
:
false
,
logging
:
false
,
});
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
res
.
status
(
statusCode
.
err
).
json
({
res
.
status
(
statusCode
.
err
).
json
({
msg
:
serverMSG
.
server_err
,
msg
:
serverMSG
.
server_err
,
content
:
"
You are aleady registered
"
,
content
:
"
You are aleady registered
"
,
...
@@ -73,10 +73,7 @@ export const postSignup = async (req, res) => {
...
@@ -73,10 +73,7 @@ export const postSignup = async (req, res) => {
}
else
{
}
else
{
db
.
User
.
create
({
email
:
email
,
nick_name
:
nick_name
},
{
logging
:
false
});
db
.
User
.
create
({
email
:
email
,
nick_name
:
nick_name
},
{
logging
:
false
});
// 로그인 페이지로 넘겨주기.
// 로그인 페이지로 넘겨주기.
res
.
status
(
statusCode
.
ok
).
json
({
res
.
redirect
(
"
/api/login
"
);
msg
:
serverMSG
.
server_ok
,
content
:
"
Successfully create user.
"
,
});
}
}
};
};
...
@@ -90,18 +87,17 @@ export const postLogin = async (req, res) => {
...
@@ -90,18 +87,17 @@ export const postLogin = async (req, res) => {
logging
:
false
,
logging
:
false
,
});
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
// token 발행
// token 발행
const
mail_token
=
jwt
.
sign
(
const
mail_token
=
jwt
.
sign
(
{
{
email
:
email
,
email
:
email
,
nick_name
:
result
[
0
][
"
nick_name
"
],
},
},
process
.
env
.
AUTH_SECRETKEY
,
process
.
env
.
AUTH_
MAIL_
SECRETKEY
,
{
{
expiresIn
:
10
*
60
,
expiresIn
:
10
*
60
,
issuer
:
"
eue.com
"
,
issuer
:
"
eue.com
"
,
subject
:
"
userInfo
"
,
subject
:
"
auth_checker
"
,
}
}
);
);
...
@@ -119,13 +115,46 @@ export const postLogin = async (req, res) => {
...
@@ -119,13 +115,46 @@ export const postLogin = async (req, res) => {
}
}
};
};
export
const
getConfirm
=
(
req
,
res
)
=>
{
export
const
getConfirm
=
async
(
req
,
res
)
=>
{
const
{
const
{
query
:
{
token
},
query
:
{
token
},
}
=
req
;
}
=
req
;
console
.
log
(
`Hi, test token :
${
token
}
`
);
try
{
res
const
decoded
=
jwt
.
verify
(
token
,
process
.
env
.
AUTH_MAIL_SECRETKEY
);
// return payload.
.
status
(
statusCode
.
ok
)
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
`Your token is :
${
token
}
`
});
const
result
=
await
db
.
User
.
findAll
({
where
:
{
email
:
decoded
.
email
},
logging
:
false
,
});
const
user
=
result
[
0
];
const
payload
=
{
email
:
user
.
email
,
nick_name
:
user
.
nick_name
,
loc_code
:
user
.
loc_code
,
};
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
"
);
}
catch
(
err
)
{
res
.
status
(
statusCode
.
err
)
.
json
({
msg
:
serverMSG
.
server_err
,
content
:
`
${
err
}
`
});
}
};
};
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