Commit e7ff22ad authored by KangMin An's avatar KangMin An
Browse files

Create & Update : 메일 발송 추가

parent 7d5c63ce
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
"mysql2": "^2.2.5", "mysql2": "^2.2.5",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"node-schedule": "^2.0.0", "node-schedule": "^2.0.0",
"nodemailer": "^6.6.2",
"pg": "^8.6.0", "pg": "^8.6.0",
"pg-hstore": "^2.3.4", "pg-hstore": "^2.3.4",
"pug": "^3.0.0", "pug": "^3.0.0",
......
...@@ -14,6 +14,7 @@ import locCodeRouter from "./routers/locCodeRouter"; ...@@ -14,6 +14,7 @@ import locCodeRouter from "./routers/locCodeRouter";
const app = express(); const app = express();
// Page Views for Development test.
app.set("view engine", "pug"); app.set("view engine", "pug");
app.set("views", path.join(__dirname, "views")); app.set("views", path.join(__dirname, "views"));
......
...@@ -79,7 +79,7 @@ export const getDataInput = (req, res) => { ...@@ -79,7 +79,7 @@ export const getDataInput = (req, res) => {
}; };
// 사용자의 데이터 가져오기 및 예측 값 전송 // 사용자의 데이터 가져오기 및 예측 값 전송
export const getUserData = (req, res) => { export const getUserWeatherData = (req, res) => {
const { const {
params: { id }, params: { id },
} = req; } = req;
......
import dotenv from "dotenv";
import nodemailer from "nodemailer";
import { serverMSG, statusCode } from "../serverinfo";
dotenv.config();
// Page for Development Test.
export const getSignup = (req, res) => {
res.render("signup", { pagename: "Sign Up" });
};
// Page for Development Test.
export const getLogin = (req, res) => {
res.render("login", { pagename: "Log In" });
};
// Function for Signup Proccess.
export const postSignup = async (req, res) => {
const {
body: { email, locCode },
} = req;
const transporter = nodemailer.createTransport({
service: process.env.NODEMAILER_SERVICE,
auth: {
type: "OAuth2",
user: process.env.NODEMAILER_USER,
clientId: process.env.NODEMAILER_GAMIL_CLIENT_ID,
clientSecret: process.env.NODEMAILER_GMAIL_CLIENT_PASSWORD,
refreshToken: process.env.NODEMAILER_GMAIL_REFRESH_TOKEN,
},
tls: {
rejectUnauthorized: false,
},
});
const mailOptions = {
from: `EUE Auth Supply <${process.env.NODEMAILER_USER}>`,
to: email,
subject: "EUE 사용자 계정 확인용 메일.",
text: `You enter locCode : ${locCode}.`,
};
try {
const mailResult = await transporter.sendMail(mailOptions);
console.log(`Mail sent - ID : ${mailResult.messageId}`);
res
.status(statusCode.ok)
.json({ msg: serverMSG.server_ok, content: mailResult.response });
} catch (err) {
console.log("Mail Sending Failuer.");
console.log(err);
res
.status(statusCode.err)
.json({ msg: serverMSG.server_err, content: err });
}
};
export const postLogin = (req, res) => {};
import express from "express"; import express from "express";
import routes from "../routes"; import routes from "../routes";
import { getDataInput, getUserData } from "../controllers/dataController"; import {
getDataInput,
getUserWeatherData,
} from "../controllers/dataController";
import { onlyPrivate } from "../middlewares"; import { onlyPrivate } from "../middlewares";
const dataRouter = express.Router(); const dataRouter = express.Router();
dataRouter.get(routes.dataInput, getDataInput); dataRouter.get(routes.dataInput, getDataInput);
dataRouter.get(routes.dataUser, onlyPrivate, getUserData); dataRouter.get(routes.dataUser, onlyPrivate, getUserWeatherData);
export default dataRouter; export default dataRouter;
import express from "express"; import express from "express";
import routes from "../routes"; import routes from "../routes";
import { getHome } from "../controllers/globalController"; import { getHome } from "../controllers/globalController";
import {
getLogin,
getSignup,
postLogin,
postSignup,
} from "../controllers/userController";
const globalRouter = express.Router(); const globalRouter = express.Router();
globalRouter.get(routes.home, getHome); globalRouter.get(routes.home, getHome);
// Authentication
globalRouter.get(routes.signup, getSignup); // For development test.
globalRouter.get(routes.login, getLogin); // For development test.
globalRouter.post(routes.signup, postSignup);
globalRouter.post(routes.login, postLogin);
export default globalRouter; export default globalRouter;
...@@ -16,7 +16,7 @@ const SIGUNGU = "/si-gun-gu"; ...@@ -16,7 +16,7 @@ const SIGUNGU = "/si-gun-gu";
const EUPMYEONDONG = "/eup-myeon-dong"; const EUPMYEONDONG = "/eup-myeon-dong";
// # Auth // # Auth
const REGISTER = "/register"; const SIGNUP = "/signup";
const LOGIN = "/login"; const LOGIN = "/login";
const EDIT_PROFILE = "/edit-profile"; const EDIT_PROFILE = "/edit-profile";
...@@ -33,7 +33,7 @@ const routes = { ...@@ -33,7 +33,7 @@ const routes = {
doe: DOE, doe: DOE,
sigungu: SIGUNGU, sigungu: SIGUNGU,
eupmyeondong: EUPMYEONDONG, eupmyeondong: EUPMYEONDONG,
register: REGISTER, signup: SIGNUP,
login: LOGIN, login: LOGIN,
editProfile: EDIT_PROFILE, editProfile: EDIT_PROFILE,
Detail: (id) => { Detail: (id) => {
......
...@@ -5,4 +5,6 @@ block content ...@@ -5,4 +5,6 @@ block content
li li
a(href=routes.data+routes.dataInput) 데이터 등록 a(href=routes.data+routes.dataInput) 데이터 등록
li li
a(href=routes.data+routes.dataOutput) 데이터 출력 a(href=routes.signup) 회원가입
\ No newline at end of file li
a(href=routes.login) 로그인
\ No newline at end of file
block content
.login-form_container
form(action=routes.login, method="post")
input(type="email", name="email", require=true, placeholder="E-mail")
input(type="submit", value="Submit")
\ No newline at end of file
block content
.signup-form_container
form(action = routes.signup, method = "post")
input(type="email", name="email", require=true, placeholder="E-mail")
input(type="number", name="locCode")
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