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
7f222365
Commit
7f222365
authored
Jul 26, 2021
by
KangMin An
Browse files
Update: User Loc Code Setting.
parent
8bcf6e01
Changes
6
Show whitespace changes
Inline
Side-by-side
server/src/controllers/userController.js
View file @
7f222365
...
@@ -7,6 +7,7 @@ import routes from "../routes";
...
@@ -7,6 +7,7 @@ import routes from "../routes";
dotenv
.
config
();
dotenv
.
config
();
// 메일 전송 처리
const
postMail
=
async
(
email
,
token
)
=>
{
const
postMail
=
async
(
email
,
token
)
=>
{
const
transporter
=
nodemailer
.
createTransport
({
const
transporter
=
nodemailer
.
createTransport
({
service
:
process
.
env
.
NODEMAILER_SERVICE
,
service
:
process
.
env
.
NODEMAILER_SERVICE
,
...
@@ -54,7 +55,12 @@ export const getLogin = (req, res) => {
...
@@ -54,7 +55,12 @@ export const getLogin = (req, res) => {
res
.
render
(
"
login
"
,
{
pagename
:
"
Log In
"
});
res
.
render
(
"
login
"
,
{
pagename
:
"
Log In
"
});
};
};
// Function for Signup Proccess.
// Page for Development Test.
export
const
getSetLoccode
=
(
req
,
res
)
=>
{
res
.
render
(
"
setLoccode
"
,
{
pagename
:
"
Set Loccode
"
});
};
// 회원 가입 처리
export
const
postSignup
=
async
(
req
,
res
)
=>
{
export
const
postSignup
=
async
(
req
,
res
)
=>
{
const
{
const
{
body
:
{
email
,
nick_name
},
body
:
{
email
,
nick_name
},
...
@@ -77,6 +83,7 @@ export const postSignup = async (req, res) => {
...
@@ -77,6 +83,7 @@ export const postSignup = async (req, res) => {
}
}
};
};
// 메일 확인용 토큰 발행 및 전송 처리
export
const
postLogin
=
async
(
req
,
res
)
=>
{
export
const
postLogin
=
async
(
req
,
res
)
=>
{
const
{
const
{
body
:
{
email
},
body
:
{
email
},
...
@@ -115,6 +122,7 @@ export const postLogin = async (req, res) => {
...
@@ -115,6 +122,7 @@ export const postLogin = async (req, res) => {
}
}
};
};
// 메일로 보낸 토큰의 유효성 검사 및 access 토큰 발행 처리
export
const
getConfirm
=
async
(
req
,
res
)
=>
{
export
const
getConfirm
=
async
(
req
,
res
)
=>
{
const
{
const
{
query
:
{
token
},
query
:
{
token
},
...
@@ -148,3 +156,36 @@ export const getConfirm = async (req, res) => {
...
@@ -148,3 +156,36 @@ export const getConfirm = async (req, res) => {
.
json
({
msg
:
serverMSG
.
server_err
,
content
:
`
${
err
}
`
});
.
json
({
msg
:
serverMSG
.
server_err
,
content
:
`
${
err
}
`
});
}
}
};
};
// 사용자의 지역 코드 설정 처리
export
const
postSetLoccode
=
async
(
req
,
res
)
=>
{
const
{
cookies
:
{
acs_token
},
body
:
{
loccode
},
}
=
req
;
const
decoded
=
jwt
.
decode
(
acs_token
);
console
.
log
(
decoded
);
await
db
.
User
.
update
(
{
loccode
:
loccode
},
{
where
:
{
email
:
decoded
.
email
}
}
);
const
payload
=
{
email
:
decoded
.
email
,
nick_name
:
decoded
.
nick_name
,
loc_code
:
loccode
,
};
const
accessT
=
jwt
.
sign
(
payload
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
,
{
expiresIn
:
"
14d
"
,
issuer
:
"
eue.com
"
,
subject
:
"
userInfo
"
,
});
res
.
status
(
statusCode
.
ok
)
.
cookie
(
"
acs_token
"
,
accessT
)
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Successfully Set Loccode
"
});
};
server/src/middlewares.js
View file @
7f222365
...
@@ -16,12 +16,11 @@ export const localmiddleware = (req, res, next) => {
...
@@ -16,12 +16,11 @@ export const localmiddleware = (req, res, next) => {
*/
*/
export
const
onlyPrivate
=
(
req
,
res
,
next
)
=>
{
export
const
onlyPrivate
=
(
req
,
res
,
next
)
=>
{
const
{
const
{
cookies
:
{
acs_
T
oken
},
cookies
:
{
acs_
t
oken
},
}
=
req
;
}
=
req
;
try
{
try
{
const
acs_decode
=
jwt
.
verify
(
acs_Token
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
);
const
acs_decode
=
jwt
.
verify
(
acs_token
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
);
console
.
log
(
`User[
${
acs_decode
.
email
}
] Data Access.`
);
next
();
next
();
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
server/src/models/user.js
View file @
7f222365
...
@@ -16,16 +16,11 @@ export class User extends Model {
...
@@ -16,16 +16,11 @@ export class User extends Model {
email
:
{
email
:
{
type
:
DataTypes
.
STRING
(
320
),
type
:
DataTypes
.
STRING
(
320
),
allowNull
:
false
,
allowNull
:
false
,
unique
:
true
,
primaryKey
:
true
,
},
},
nick_name
:
{
nick_name
:
{
type
:
DataTypes
.
STRING
(
16
),
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
allowNull
:
false
,
unique
:
true
,
},
using_oauth
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
},
},
using_aircon
:
{
using_aircon
:
{
type
:
DataTypes
.
BOOLEAN
,
type
:
DataTypes
.
BOOLEAN
,
...
...
server/src/routers/globalRouter.js
View file @
7f222365
...
@@ -4,10 +4,13 @@ import { getHome } from "../controllers/globalController";
...
@@ -4,10 +4,13 @@ import { getHome } from "../controllers/globalController";
import
{
import
{
getConfirm
,
getConfirm
,
getLogin
,
getLogin
,
getSetLoccode
,
getSignup
,
getSignup
,
postLogin
,
postLogin
,
postSetLoccode
,
postSignup
,
postSignup
,
}
from
"
../controllers/userController
"
;
}
from
"
../controllers/userController
"
;
import
{
onlyPrivate
}
from
"
../middlewares
"
;
const
globalRouter
=
express
.
Router
();
const
globalRouter
=
express
.
Router
();
...
@@ -16,8 +19,11 @@ globalRouter.get("/", getHome); // For development test.
...
@@ -16,8 +19,11 @@ globalRouter.get("/", getHome); // For development test.
// Authentication
// Authentication
globalRouter
.
get
(
routes
.
signup
,
getSignup
);
// For development test.
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
.
get
(
routes
.
setLoccode
,
onlyPrivate
,
getSetLoccode
);
// 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
);
globalRouter
.
get
(
routes
.
confirm
,
getConfirm
);
globalRouter
.
post
(
routes
.
setLoccode
,
onlyPrivate
,
postSetLoccode
);
export
default
globalRouter
;
export
default
globalRouter
;
server/src/routes.js
View file @
7f222365
...
@@ -17,6 +17,7 @@ const SIGNUP = "/signup";
...
@@ -17,6 +17,7 @@ const SIGNUP = "/signup";
const
LOGIN
=
"
/login
"
;
const
LOGIN
=
"
/login
"
;
const
CONFIRM
=
"
/confirm
"
;
const
CONFIRM
=
"
/confirm
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
const
SET_LOCCODE
=
"
/set-loccode
"
;
// # Detail Object
// # Detail Object
const
DETAIL
=
"
/:id
"
;
const
DETAIL
=
"
/:id
"
;
...
@@ -32,6 +33,7 @@ const routes = {
...
@@ -32,6 +33,7 @@ const routes = {
login
:
LOGIN
,
login
:
LOGIN
,
confirm
:
CONFIRM
,
confirm
:
CONFIRM
,
editProfile
:
EDIT_PROFILE
,
editProfile
:
EDIT_PROFILE
,
setLoccode
:
SET_LOCCODE
,
Detail
:
(
id
)
=>
{
Detail
:
(
id
)
=>
{
if
(
id
)
{
if
(
id
)
{
return
`/
${
id
}
`
;
return
`/
${
id
}
`
;
...
...
server/src/views/setLoccode.pug
0 → 100644
View file @
7f222365
block content
.signup-form_container
form(action = routes.base + routes.setLoccode, method = "post")
input(type="number", name="loccode", require=true, placeholder="Local Code.")
input(type="submit", value="Submit")
\ No newline at end of file
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