Commit 7f222365 authored by KangMin An's avatar KangMin An
Browse files

Update: User Loc Code Setting.

parent 8bcf6e01
...@@ -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" });
};
...@@ -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_Token }, cookies: { acs_token },
} = 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);
......
...@@ -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,
......
...@@ -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;
...@@ -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}`;
......
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment