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

Update : Test Pages. Send Mail with Token.

parent 3bddb53f
import db from "../db/index";
import { serverMSG, statusCode } from "../serverinfo";
// Do Code에 대한 GET 요청 처리
export const getDoe = async (req, res) => {
const result = await db.Doe.findAll({ logging: false });
if (result) {
res.status(statusCode.ok).json({ DO: result });
} else {
res.status(statusCode.err).send(serverMSG.server_err);
}
};
// SGG Code에 대한 GET 요청 처리
export const getSGG = async (req, res) => {
const {
params: { id },
} = req;
const result = await db.Sgg.findAll({
where: { code_doe: Number(id) },
logging: false,
});
if (result) {
res.status(statusCode.ok).json({ DO: Number(id), SGG: result });
} else {
console.log(result);
res.status(statusCode.err).send(serverMSG.server_err);
}
};
// EMD Code에 대한 GET 요청 처리
export const getEMD = async (req, res) => {
const {
params: { id },
} = req;
const result = await db.Emd.findAll({
where: { code_sgg: Number(id) },
logging: false,
});
if (result) {
res.status(statusCode.ok).json({ SGG: Number(id), EMD: result });
} else {
console.log(result);
res.status(statusCode.err).send(serverMSG.server_err);
}
};
...@@ -26,9 +26,11 @@ const postMail = async (email, token) => { ...@@ -26,9 +26,11 @@ const postMail = async (email, token) => {
from: `EUE Auth Supply <${process.env.NODEMAILER_USER}>`, from: `EUE Auth Supply <${process.env.NODEMAILER_USER}>`,
to: email, to: email,
subject: "EUE 사용자 계정 확인용 메일.", subject: "EUE 사용자 계정 확인용 메일.",
html: `<a href="${process.env.HOST}:${process.env.PORT}${ html: `<a href="${process.env.PROTOCOL}://${process.env.HOST}:${
routes.base + routes.confirm process.env.PORT
}?token=${token}">${process.env.HOST}:${process.env.PORT}${ }${routes.base + routes.confirm}?token=${token}">${
process.env.PROTOCOL
}://${process.env.HOST}:${process.env.PORT}${
routes.base + routes.confirm routes.base + routes.confirm
}?token=${token}</a>`, }?token=${token}</a>`,
}; };
...@@ -36,15 +38,9 @@ const postMail = async (email, token) => { ...@@ -36,15 +38,9 @@ const postMail = async (email, token) => {
try { try {
const mailResult = await transporter.sendMail(mailOptions); const mailResult = await transporter.sendMail(mailOptions);
console.log(`Mail sent - ID : ${mailResult.messageId}`); console.log(`Mail sent - ID : ${mailResult.messageId}`);
res
.status(statusCode.ok)
.json({ msg: serverMSG.server_ok, content: mailResult.response });
} catch (err) { } catch (err) {
console.log("Mail Sending Failuer."); console.log("Mail Sending Failuer.");
console.log(err); console.log(err);
res
.status(statusCode.err)
.json({ msg: serverMSG.server_err, content: err });
} }
}; };
...@@ -64,12 +60,12 @@ export const postSignup = async (req, res) => { ...@@ -64,12 +60,12 @@ export const postSignup = async (req, res) => {
body: { email, nick_name }, body: { email, nick_name },
} = req; } = req;
const result = db.User.findOne({ const result = await db.User.findOne({
where: { email: email }, where: { email: email },
logging: false, logging: false,
}); });
if (result.length != 0) { if (result) {
res.status(statusCode.err).json({ res.status(statusCode.err).json({
msg: serverMSG.server_err, msg: serverMSG.server_err,
content: "You are aleady registered", content: "You are aleady registered",
...@@ -84,22 +80,22 @@ export const postSignup = async (req, res) => { ...@@ -84,22 +80,22 @@ export const postSignup = async (req, res) => {
} }
}; };
export const postLogin = (req, res) => { export const postLogin = async (req, res) => {
const { const {
body: { email }, body: { email },
} = req; } = req;
const result = db.User.findAll({ const result = await db.User.findAll({
where: { email: email }, where: { email: email },
logging: false, logging: false,
}); });
if (result.length != 0) { if (result) {
// token 발행 // token 발행
const mail_token = jwt.sign( const mail_token = jwt.sign(
{ {
email: email, email: email,
nick_name: resutl[0]["nick_name"], nick_name: result[0]["nick_name"],
}, },
process.env.AUTH_SECRETKEY, process.env.AUTH_SECRETKEY,
{ {
...@@ -125,8 +121,11 @@ export const postLogin = (req, res) => { ...@@ -125,8 +121,11 @@ export const postLogin = (req, res) => {
export const getConfirm = (req, res) => { export const getConfirm = (req, res) => {
const { const {
params: { token }, query: { token },
} = req; } = req;
console.log(`Hi, test token : ${token}`); console.log(`Hi, test token : ${token}`);
res
.status(statusCode.ok)
.json({ msg: serverMSG.server_ok, content: `Your token is : ${token}` });
}; };
...@@ -23,10 +23,6 @@ export class User extends Model { ...@@ -23,10 +23,6 @@ export class User extends Model {
allowNull: false, allowNull: false,
unique: true, unique: true,
}, },
password: {
type: DataTypes.STRING(20),
allowNull: false,
},
}, },
{ {
sequelize, sequelize,
......
block content block content
.login-form_container .login-form_container
form(action=routes.login, method="post") form(action=routes.base + routes.login, method="post")
input(type="email", name="email", require=true, placeholder="E-mail") input(type="email", name="email", require=true, placeholder="E-mail")
input(type="submit", value="Submit") input(type="submit", value="Submit")
\ No newline at end of file
block content block content
.signup-form_container .signup-form_container
form(action = routes.signup, method = "post") form(action = routes.base + routes.signup, method = "post")
input(type="email", name="email", require=true, placeholder="E-mail") input(type="email", name="email", require=true, placeholder="E-mail")
input(type="number", name="locCode") input(type="text", name="nick_name")
input(type="submit", value="Submit") 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