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
Hide whitespace changes
Inline
Side-by-side
server/src/controllers/userController.js
View file @
7f222365
...
...
@@ -7,6 +7,7 @@ import routes from "../routes";
dotenv
.
config
();
// 메일 전송 처리
const
postMail
=
async
(
email
,
token
)
=>
{
const
transporter
=
nodemailer
.
createTransport
({
service
:
process
.
env
.
NODEMAILER_SERVICE
,
...
...
@@ -54,7 +55,12 @@ export const getLogin = (req, res) => {
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
)
=>
{
const
{
body
:
{
email
,
nick_name
},
...
...
@@ -77,6 +83,7 @@ export const postSignup = async (req, res) => {
}
};
// 메일 확인용 토큰 발행 및 전송 처리
export
const
postLogin
=
async
(
req
,
res
)
=>
{
const
{
body
:
{
email
},
...
...
@@ -115,6 +122,7 @@ export const postLogin = async (req, res) => {
}
};
// 메일로 보낸 토큰의 유효성 검사 및 access 토큰 발행 처리
export
const
getConfirm
=
async
(
req
,
res
)
=>
{
const
{
query
:
{
token
},
...
...
@@ -148,3 +156,36 @@ export const getConfirm = async (req, res) => {
.
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) => {
*/
export
const
onlyPrivate
=
(
req
,
res
,
next
)
=>
{
const
{
cookies
:
{
acs_
T
oken
},
cookies
:
{
acs_
t
oken
},
}
=
req
;
try
{
const
acs_decode
=
jwt
.
verify
(
acs_Token
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
);
console
.
log
(
`User[
${
acs_decode
.
email
}
] Data Access.`
);
const
acs_decode
=
jwt
.
verify
(
acs_token
,
process
.
env
.
AUTH_ACCESS_SECRETKEY
);
next
();
}
catch
(
error
)
{
console
.
log
(
error
);
...
...
server/src/models/user.js
View file @
7f222365
...
...
@@ -16,16 +16,11 @@ export class User extends Model {
email
:
{
type
:
DataTypes
.
STRING
(
320
),
allowNull
:
false
,
unique
:
true
,
primaryKey
:
true
,
},
nick_name
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
unique
:
true
,
},
using_oauth
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
},
using_aircon
:
{
type
:
DataTypes
.
BOOLEAN
,
...
...
server/src/routers/globalRouter.js
View file @
7f222365
...
...
@@ -4,10 +4,13 @@ import { getHome } from "../controllers/globalController";
import
{
getConfirm
,
getLogin
,
getSetLoccode
,
getSignup
,
postLogin
,
postSetLoccode
,
postSignup
,
}
from
"
../controllers/userController
"
;
import
{
onlyPrivate
}
from
"
../middlewares
"
;
const
globalRouter
=
express
.
Router
();
...
...
@@ -16,8 +19,11 @@ globalRouter.get("/", getHome); // For development test.
// Authentication
globalRouter
.
get
(
routes
.
signup
,
getSignup
);
// 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
.
login
,
postLogin
);
globalRouter
.
get
(
routes
.
confirm
,
getConfirm
);
globalRouter
.
post
(
routes
.
setLoccode
,
onlyPrivate
,
postSetLoccode
);
export
default
globalRouter
;
server/src/routes.js
View file @
7f222365
...
...
@@ -17,6 +17,7 @@ const SIGNUP = "/signup";
const
LOGIN
=
"
/login
"
;
const
CONFIRM
=
"
/confirm
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
const
SET_LOCCODE
=
"
/set-loccode
"
;
// # Detail Object
const
DETAIL
=
"
/:id
"
;
...
...
@@ -32,6 +33,7 @@ const routes = {
login
:
LOGIN
,
confirm
:
CONFIRM
,
editProfile
:
EDIT_PROFILE
,
setLoccode
:
SET_LOCCODE
,
Detail
:
(
id
)
=>
{
if
(
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