Commit 1e5a8949 authored by KangMin An's avatar KangMin An
Browse files

Merge branch 'kangmin' into premaster.

parents 440d957b 41352d1f
...@@ -25,9 +25,12 @@ const postMail = async (email, token) => { ...@@ -25,9 +25,12 @@ const postMail = async (email, token) => {
from: `EUE Auth Supply <${envs.api.nodemailer.user}>`, from: `EUE Auth Supply <${envs.api.nodemailer.user}>`,
to: email, to: email,
subject: "EUE 사용자 계정 확인용 메일.", subject: "EUE 사용자 계정 확인용 메일.",
html: `<a href="${envs.server.protocol}://${envs.server.host}:${envs.server.port html: `<a href="${envs.server.protocol}://${envs.server.host}:${
}${routes.base + routes.confirm}?token=${token}">${envs.server.protocol envs.server.port
}://${envs.server.host}:${envs.server.port}${routes.base + routes.confirm }${routes.base + routes.confirm}?token=${token}">${
envs.server.protocol
}://${envs.server.host}:${envs.server.port}${
routes.base + routes.confirm
}?token=${token}</a>`, }?token=${token}</a>`,
}; };
...@@ -124,7 +127,7 @@ export const postLogin = async (req, res) => { ...@@ -124,7 +127,7 @@ export const postLogin = async (req, res) => {
// 로그아웃 요청 처리 // 로그아웃 요청 처리
export const getLogout = (req, res) => { export const getLogout = (req, res) => {
res.clearCookie("acs_token") res.clearCookie("acs_token");
}; };
// 메일로 보낸 토큰의 유효성 검사 및 access 토큰 발행 처리 // 메일로 보낸 토큰의 유효성 검사 및 access 토큰 발행 처리
...@@ -152,9 +155,10 @@ export const getConfirm = async (req, res) => { ...@@ -152,9 +155,10 @@ export const getConfirm = async (req, res) => {
subject: "userInfo", subject: "userInfo",
}); });
res.cookie("acs_token", accessT) res
.cookie("acs_token", accessT)
.redirect( .redirect(
"http://localhost:3000/first-local-code" `${envs.client.protocol}://${envs.client.host}:${envs.client.port}/first-local-code`
); );
} catch (err) { } catch (err) {
res.json({ msg: resForm.msg.err, contents: { error: err } }); res.json({ msg: resForm.msg.err, contents: { error: err } });
...@@ -223,7 +227,7 @@ export const getUserInfo = async (req, res) => { ...@@ -223,7 +227,7 @@ export const getUserInfo = async (req, res) => {
export const postEditProfile = async (req, res) => { export const postEditProfile = async (req, res) => {
const { const {
cookies: { acs_token }, cookies: { acs_token },
body: { nick_name, loc_code, using_aircon }, body: { nick_name, loc_code },
} = req; } = req;
try { try {
...@@ -237,15 +241,11 @@ export const postEditProfile = async (req, res) => { ...@@ -237,15 +241,11 @@ export const postEditProfile = async (req, res) => {
let new_nick_name = nick_name ? nick_name : user.nick_name; let new_nick_name = nick_name ? nick_name : user.nick_name;
let new_loc_code = loc_code ? Number(loc_code) : Number(user.loc_code); let new_loc_code = loc_code ? Number(loc_code) : Number(user.loc_code);
let new_using_aircon = using_aircon
? using_aircon === 'true'
: user.using_aircon;
await db.User.update( await db.User.update(
{ {
nick_name: new_nick_name, nick_name: new_nick_name,
loc_code: new_loc_code, loc_code: new_loc_code,
using_aircon: new_using_aircon,
}, },
{ where: { email: decoded.email } } { where: { email: decoded.email } }
); );
...@@ -263,3 +263,28 @@ export const postEditProfile = async (req, res) => { ...@@ -263,3 +263,28 @@ export const postEditProfile = async (req, res) => {
res.json({ msg: resForm.msg.err, contents: { error: err } }); res.json({ msg: resForm.msg.err, contents: { error: err } });
} }
}; };
// 에어컨 사용 변경 요청 처리
export const getToggleAircon = async (req, res) => {
const {
cookies: { acs_token },
} = req;
try {
const decoded = jwt.decode(acs_token);
const result_preuser = await db.User.findAll({
where: { email: decoded.email },
logging: false,
});
await db.User.update(
{ using_aircon: !result_preuser[0].using_aircon },
{ where: { email: decoded.email } }
);
res.json({ msg: resForm.msg.ok, contents: {} });
} catch (err) {
console.log(err);
res.json({ msg: resForm.msg.err, contents: { error: err } });
}
};
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
postLogin, postLogin,
getLogout, getLogout,
postSignup, postSignup,
getToggleAircon,
} from "../controllers/userController"; } from "../controllers/userController";
import { onlyPrivate } from "../middlewares"; import { onlyPrivate } from "../middlewares";
...@@ -31,5 +32,6 @@ globalRouter.get(routes.confirm, getConfirm); ...@@ -31,5 +32,6 @@ globalRouter.get(routes.confirm, getConfirm);
// User Info // User Info
globalRouter.get(routes.userinfo, onlyPrivate, getUserInfo); globalRouter.get(routes.userinfo, onlyPrivate, getUserInfo);
globalRouter.post(routes.editProfile, onlyPrivate, postEditProfile); globalRouter.post(routes.editProfile, onlyPrivate, postEditProfile);
globalRouter.post(routes.toggleAircon, onlyPrivate, getToggleAircon);
export default globalRouter; export default globalRouter;
...@@ -22,7 +22,7 @@ const CONFIRM = "/confirm"; ...@@ -22,7 +22,7 @@ const CONFIRM = "/confirm";
// # User Info // # User Info
const USER_INFO = "/user-info"; const USER_INFO = "/user-info";
const SET_LOCCODE = "/set-loccode"; const TOGGLE_AIRCON = "/toggle-aircon";
const EDIT_PROFILE = "/edit-profile"; const EDIT_PROFILE = "/edit-profile";
// # Detail Object // # Detail Object
...@@ -41,7 +41,7 @@ const routes = { ...@@ -41,7 +41,7 @@ const routes = {
confirm: CONFIRM, confirm: CONFIRM,
userinfo: USER_INFO, userinfo: USER_INFO,
editProfile: EDIT_PROFILE, editProfile: EDIT_PROFILE,
setLoccode: SET_LOCCODE, toggleAircon: TOGGLE_AIRCON,
Detail: (id) => { Detail: (id) => {
if (id) { if (id) {
return `/${id}`; return `/${id}`;
......
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