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";
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" });
};
......@@ -16,12 +16,11 @@ export const localmiddleware = (req, res, next) => {
*/
export const onlyPrivate = (req, res, next) => {
const {
cookies: { acs_Token },
cookies: { acs_token },
} = 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);
......
......@@ -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,
......
......@@ -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;
......@@ -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}`;
......
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