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
Hide whitespace changes
Inline
Side-by-side
server/package.json
View file @
1c096966
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
"dotenv"
:
"^8.2.0"
,
"dotenv"
:
"^8.2.0"
,
"express"
:
"^4.17.1"
,
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"helmet"
:
"^4.1.1"
,
"jsonwebtoken"
:
"^8.5.1"
,
"morgan"
:
"^1.10.0"
,
"morgan"
:
"^1.10.0"
,
"mysql2"
:
"^2.2.5"
,
"mysql2"
:
"^2.2.5"
,
"node-fetch"
:
"^2.6.1"
,
"node-fetch"
:
"^2.6.1"
,
...
...
server/src/controllers/userController.js
View file @
1c096966
import
db
from
"
../db/index
"
;
import
db
from
"
../db/index
"
;
import
dotenv
from
"
dotenv
"
;
import
dotenv
from
"
dotenv
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
nodemailer
from
"
nodemailer
"
;
import
nodemailer
from
"
nodemailer
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
routes
from
"
../routes
"
;
dotenv
.
config
();
dotenv
.
config
();
...
@@ -24,7 +26,11 @@ const postMail = async (email, token) => {
...
@@ -24,7 +26,11 @@ const postMail = async (email, token) => {
from
:
`EUE Auth Supply <
${
process
.
env
.
NODEMAILER_USER
}
>`
,
from
:
`EUE Auth Supply <
${
process
.
env
.
NODEMAILER_USER
}
>`
,
to
:
email
,
to
:
email
,
subject
:
"
EUE 사용자 계정 확인용 메일.
"
,
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
{
try
{
...
@@ -55,7 +61,7 @@ export const getLogin = (req, res) => {
...
@@ -55,7 +61,7 @@ export const getLogin = (req, res) => {
// Function for Signup Proccess.
// Function for Signup Proccess.
export
const
postSignup
=
async
(
req
,
res
)
=>
{
export
const
postSignup
=
async
(
req
,
res
)
=>
{
const
{
const
{
body
:
{
email
,
locCod
e
},
body
:
{
email
,
nick_nam
e
},
}
=
req
;
}
=
req
;
const
result
=
db
.
User
.
findOne
({
const
result
=
db
.
User
.
findOne
({
...
@@ -63,14 +69,18 @@ export const postSignup = async (req, res) => {
...
@@ -63,14 +69,18 @@ export const postSignup = async (req, res) => {
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
"
,
});
});
}
else
{
}
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) => {
...
@@ -79,25 +89,44 @@ export const postLogin = (req, res) => {
body
:
{
email
},
body
:
{
email
},
}
=
req
;
}
=
req
;
const
result
=
db
.
User
.
find
One
({
const
result
=
db
.
User
.
find
All
({
where
:
{
email
:
email
},
where
:
{
email
:
email
},
logging
:
false
,
logging
:
false
,
});
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
// token 발행
// 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
res
.
status
(
statusCode
.
ok
)
.
status
(
statusCode
.
ok
)
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Send Mail Successfully.
"
});
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Send Mail Successfully.
"
});
}
else
{
}
else
{
res
res
.
status
(
statusCode
.
err
).
json
({
.
status
(
statusCode
.
err
)
msg
:
serverMSG
.
server_err
,
.
json
({
content
:
"
You are not one of our user yet.
"
,
msg
:
serverMSG
.
server_err
,
});
content
:
"
You are still not our user.
"
,
});
}
}
};
};
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 {
...
@@ -18,6 +18,11 @@ export class User extends Model {
allowNull
:
false
,
allowNull
:
false
,
primaryKey
:
true
,
primaryKey
:
true
,
},
},
nick_name
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
unique
:
true
,
},
password
:
{
password
:
{
type
:
DataTypes
.
STRING
(
20
),
type
:
DataTypes
.
STRING
(
20
),
allowNull
:
false
,
allowNull
:
false
,
...
...
server/src/routers/globalRouter.js
View file @
1c096966
...
@@ -2,6 +2,7 @@ import express from "express";
...
@@ -2,6 +2,7 @@ import express from "express";
import
routes
from
"
../routes
"
;
import
routes
from
"
../routes
"
;
import
{
getHome
}
from
"
../controllers/globalController
"
;
import
{
getHome
}
from
"
../controllers/globalController
"
;
import
{
import
{
getConfirm
,
getLogin
,
getLogin
,
getSignup
,
getSignup
,
postLogin
,
postLogin
,
...
@@ -17,5 +18,6 @@ globalRouter.get(routes.signup, getSignup); // For development test.
...
@@ -17,5 +18,6 @@ globalRouter.get(routes.signup, getSignup); // For development test.
globalRouter
.
get
(
routes
.
login
,
getLogin
);
// For development test.
globalRouter
.
get
(
routes
.
login
,
getLogin
);
// For development test.
globalRouter
.
post
(
routes
.
signup
,
postSignup
);
globalRouter
.
post
(
routes
.
signup
,
postSignup
);
globalRouter
.
post
(
routes
.
login
,
postLogin
);
globalRouter
.
post
(
routes
.
login
,
postLogin
);
globalRouter
.
get
(
routes
.
confirm
,
getConfirm
);
export
default
globalRouter
;
export
default
globalRouter
;
server/src/routes.js
View file @
1c096966
...
@@ -15,6 +15,7 @@ const LOCCODE = "/loccode";
...
@@ -15,6 +15,7 @@ const LOCCODE = "/loccode";
// # Auth
// # Auth
const
SIGNUP
=
"
/signup
"
;
const
SIGNUP
=
"
/signup
"
;
const
LOGIN
=
"
/login
"
;
const
LOGIN
=
"
/login
"
;
const
CONFIRM
=
"
/confirm
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
// # Detail Object
// # Detail Object
...
@@ -29,6 +30,7 @@ const routes = {
...
@@ -29,6 +30,7 @@ const routes = {
locCode
:
LOCCODE
,
locCode
:
LOCCODE
,
signup
:
SIGNUP
,
signup
:
SIGNUP
,
login
:
LOGIN
,
login
:
LOGIN
,
confirm
:
CONFIRM
,
editProfile
:
EDIT_PROFILE
,
editProfile
:
EDIT_PROFILE
,
Detail
:
(
id
)
=>
{
Detail
:
(
id
)
=>
{
if
(
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