오늘 한일 이메일인증을 통한 아이디찾기/비밀번호 변경,
AccessToken / RefreshToken 발급 하기
// 이메일 인증
const emailauth = async (req, res, next) => {
try {
const { email } = req.body;
// 인증메일 (번호)
const emailAuth = Math.floor(Math.random() * 10000);
await userService.emailauth(email, emailAuth);
const transporter = nodemailer.createTransport({
service: NODEMAILER_SERVICE,
host: process.env.NODEMAILER_HOST,
port: process.env.NODEMAILER_PORT,
secure: false,
auth: {
user: process.env.NODEMAILER_USER,
pass: process.env.NODEMAILER_PASS,
},
});
let info = await transporter.sendMail({
from: `"Paper 환영합니다" <${process.env.NODEMAILER_USER}>`,
to: email,
subject: '[Paper] 인증번호가 도착했습니다.',
text: `${emailAuth}`,
});
res.status(200).json({
result: true,
});
} catch (error) {
console.log(error);
next(error);
}
};
exports.emailauth = emailauth;
// 이메일 인증 체크
const check_emaliauth = async (req, res, next) => {
try {
const { emailAuth } = req.body;
const text = await userService.check_emaliauth(emailAuth);
await userService.delet_check_emaliauth(emailAuth);
console.log(text.emailAuth);
if (Number(emailAuth) === text.emailAuth) {
return res.status(200).send({
result: true,
});
}
res.status(400).send({
result: false,
});
} catch (error) {
console.log(error);
next(error);
}
};
exports.check_emaliauth = check_emaliauth;
// 비밀번호 변경
const change_password = async (req, res, next) => {
try {
const { email, password } = req.body;
await userService.change_password(email, password);
res.status(200).send({
result: true,
});
} catch (error) {
console.log(error);
next(error);
}
};
----------------------로그인 되어있을떄----------------------------
// 이메일 인증 (로그인 시)
const login_emailauth = async (req, res, next) => {
try {
const { user } = res.locals;
// 인증메일 (번호)
const emailAuth = Math.floor(Math.random() * 10000);
await userService.login_emailauth(user, emailAuth);
const transporter = nodemailer.createTransport({
service: NODEMAILER_SERVICE,
host: process.env.NODEMAILER_HOST,
port: process.env.NODEMAILER_PORT,
secure: false,
auth: {
user: process.env.NODEMAILER_USER,
pass: process.env.NODEMAILER_PASS,
},
});
let info = await transporter.sendMail({
from: `"Paper 환영합니다" <${process.env.NODEMAILER_USER}>`,
to: user.email,
subject: '[Paper] 인증번호가 도착했습니다.',
text: `${emailAuth}`,
});
res.status(200).json({
result: true,
});
} catch (error) {
console.log(error);
next(error);
}
};
exports.login_emailauth = login_emailauth;
// 이메일 인증 체크(로그인 시)
const login_check_emaliauth = async (req, res, next) => {
try {
const { user } = res.locals;
const { emailAuth } = req.body;
const text = await userService.login_check_emaliauth(user);
await userService.login_delet_check_emaliauth(user);
if (Number(emailAuth) === text.emailAuth) {
res.status(200).send({
result: true,
});
return;
}
res.status(400).send({
result: false,
});
} catch (error) {
console.log(error);
next(error);
}
};
exports.login_check_emaliauth = login_check_emaliauth;
// 비밀번호 변경(로그인 시)
const login_change_password = async (req, res, next) => {
try {
const { user } = res.locals;
const { password } = req.body;
await userService.login_change_password(user, password);
res.status(200).send({
result: true,
});
} catch (error) {
console.log(error);
next(error);
}
};
exports.login_change_password = login_change_password;