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
1c096966
Commit
1c096966
authored
Jul 21, 2021
by
KangMin An
Browse files
Update : User 인증 과정 수정(진행중).
parent
2c0524e1
Changes
5
Show whitespace changes
Inline
Side-by-side
server/package.json
View file @
1c096966
...
...
@@ -27,6 +27,7 @@
"dotenv"
:
"^8.2.0"
,
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"jsonwebtoken"
:
"^8.5.1"
,
"morgan"
:
"^1.10.0"
,
"mysql2"
:
"^2.2.5"
,
"node-fetch"
:
"^2.6.1"
,
...
...
server/src/controllers/userController.js
View file @
1c096966
import
db
from
"
../db/index
"
;
import
dotenv
from
"
dotenv
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
nodemailer
from
"
nodemailer
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
routes
from
"
../routes
"
;
dotenv
.
config
();
...
...
@@ -24,7 +26,11 @@ const postMail = async (email, token) => {
from
:
`EUE Auth Supply <
${
process
.
env
.
NODEMAILER_USER
}
>`
,
to
:
email
,
subject
:
"
EUE 사용자 계정 확인용 메일.
"
,
text
:
`You enter locCode :
${
locCode
}
.`
,
html
:
`<a href="
${
process
.
env
.
HOST
}
:
${
process
.
env
.
PORT
}${
routes
.
base
+
routes
.
confirm
}
?token=
${
token
}
">
${
process
.
env
.
HOST
}
:
${
process
.
env
.
PORT
}${
routes
.
base
+
routes
.
confirm
}
?token=
${
token
}
</a>`
,
};
try
{
...
...
@@ -55,7 +61,7 @@ export const getLogin = (req, res) => {
// Function for Signup Proccess.
export
const
postSignup
=
async
(
req
,
res
)
=>
{
const
{
body
:
{
email
,
locCod
e
},
body
:
{
email
,
nick_nam
e
},
}
=
req
;
const
result
=
db
.
User
.
findOne
({
...
...
@@ -63,14 +69,18 @@ export const postSignup = async (req, res) => {
logging
:
false
,
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
res
.
status
(
statusCode
.
err
).
json
({
msg
:
serverMSG
.
server_err
,
content
:
"
You are aleady registered
"
,
});
}
else
{
db
.
User
.
create
({
email
:
email
,
locCode
:
locCod
e
},
{
logging
:
false
});
db
.
User
.
create
({
email
:
email
,
nick_name
:
nick_nam
e
},
{
logging
:
false
});
// 로그인 페이지로 넘겨주기.
res
.
status
(
statusCode
.
ok
).
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Successfully create user.
"
,
});
}
};
...
...
@@ -79,25 +89,44 @@ export const postLogin = (req, res) => {
body
:
{
email
},
}
=
req
;
const
result
=
db
.
User
.
find
One
({
const
result
=
db
.
User
.
find
All
({
where
:
{
email
:
email
},
logging
:
false
,
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
// token 발행
const
token
=
"
ex Token
"
;
const
mail_token
=
jwt
.
sign
(
{
email
:
email
,
nick_name
:
resutl
[
0
][
"
nick_name
"
],
},
process
.
env
.
AUTH_SECRETKEY
,
{
expiresIn
:
10
*
60
,
issuer
:
"
eue.com
"
,
subject
:
"
userInfo
"
,
}
);
// 토큰이 포함된 로그인 링크 전송
postLogin
(
email
,
token
);
postMail
(
email
,
mail_token
);
res
.
status
(
statusCode
.
ok
)
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Send Mail Successfully.
"
});
}
else
{
res
.
status
(
statusCode
.
err
)
.
json
({
res
.
status
(
statusCode
.
err
).
json
({
msg
:
serverMSG
.
server_err
,
content
:
"
You are
still not
our user.
"
,
content
:
"
You are
not one of
our user
yet
.
"
,
});
}
};
export
const
getConfirm
=
(
req
,
res
)
=>
{
const
{
params
:
{
token
},
}
=
req
;
console
.
log
(
`Hi, test token :
${
token
}
`
);
};
server/src/models/user.js
View file @
1c096966
...
...
@@ -18,6 +18,11 @@ export class User extends Model {
allowNull
:
false
,
primaryKey
:
true
,
},
nick_name
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
unique
:
true
,
},
password
:
{
type
:
DataTypes
.
STRING
(
20
),
allowNull
:
false
,
...
...
server/src/routers/globalRouter.js
View file @
1c096966
...
...
@@ -2,6 +2,7 @@ import express from "express";
import
routes
from
"
../routes
"
;
import
{
getHome
}
from
"
../controllers/globalController
"
;
import
{
getConfirm
,
getLogin
,
getSignup
,
postLogin
,
...
...
@@ -17,5 +18,6 @@ globalRouter.get(routes.signup, getSignup); // For development test.
globalRouter
.
get
(
routes
.
login
,
getLogin
);
// For development test.
globalRouter
.
post
(
routes
.
signup
,
postSignup
);
globalRouter
.
post
(
routes
.
login
,
postLogin
);
globalRouter
.
get
(
routes
.
confirm
,
getConfirm
);
export
default
globalRouter
;
server/src/routes.js
View file @
1c096966
...
...
@@ -15,6 +15,7 @@ const LOCCODE = "/loccode";
// # Auth
const
SIGNUP
=
"
/signup
"
;
const
LOGIN
=
"
/login
"
;
const
CONFIRM
=
"
/confirm
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
// # Detail Object
...
...
@@ -29,6 +30,7 @@ const routes = {
locCode
:
LOCCODE
,
signup
:
SIGNUP
,
login
:
LOGIN
,
confirm
:
CONFIRM
,
editProfile
:
EDIT_PROFILE
,
Detail
:
(
id
)
=>
{
if
(
id
)
{
...
...
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