From fcaa4b99584fc76f06e5e6bce5260a5771816298 Mon Sep 17 00:00:00 2001 From: Juuunyeok Date: Mon, 19 Feb 2024 18:31:59 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=ED=95=9C,=20=EC=9E=84=EC=8B=9C?= =?UTF-8?q?=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=2012=EC=9E=90=EB=A6=AC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/sms.controller.js | 13 +++++++++++-- src/models/sms.dao.js | 6 ++++++ src/services/user.service.js | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/controllers/sms.controller.js b/src/controllers/sms.controller.js index f00a7a4..04ef8ad 100644 --- a/src/controllers/sms.controller.js +++ b/src/controllers/sms.controller.js @@ -1,13 +1,22 @@ import pkg from 'solapi'; const {SolapiMessageService} = pkg; -import {createCode, findCode, deleteCode} from '../models/sms.dao'; +import {createCode, findCode, deleteCode, findPhoneNumber} from '../models/sms.dao'; import jwt from 'jsonwebtoken' export const sendVerificationCode= async (req, res)=>{ let codecheck; try { - const messageService = new SolapiMessageService(process.env.SMS_KEY, process.env.SMS_SECRET); const { phone_number } = req.body; + const checkPhone = await findPhoneNumber(phone_number); + if (checkPhone) { + return res.status(200).json({ + success: false, + code: 'DUPLICATE_PHONE_NUMBER', + message: '중복된 전화번호입니다.', + }); + } + const messageService = new SolapiMessageService(process.env.SMS_KEY, process.env.SMS_SECRET); + // 인증코드 생성 const verificationCode = Math.floor(1000000 + Math.random() * 9000000); // 7자리 diff --git a/src/models/sms.dao.js b/src/models/sms.dao.js index 339dddc..b06be6e 100644 --- a/src/models/sms.dao.js +++ b/src/models/sms.dao.js @@ -24,5 +24,11 @@ export const findCode = async (id) => { export const deleteCode = async (id) => { const [rows] = await pool.query('DELETE FROM sms WHERE id = ?',[id]); + return rows[0]; +} + +export const findPhoneNumber = async (phone_number) => { + const [rows] = await pool.query('SELECT * FROM user WHERE phone_number = ?', [phone_number]); + return rows[0]; } \ No newline at end of file diff --git a/src/services/user.service.js b/src/services/user.service.js index d747afb..c7698ba 100644 --- a/src/services/user.service.js +++ b/src/services/user.service.js @@ -201,7 +201,7 @@ export const tempPasswordService = async (name, phone_number, email) => { } // 임시 비밀번호 생성 (영어 대소문자, 숫자 혼합) - const tempPassword = Math.random().toString(36).slice(2) + Math.random().toString(36).toUpperCase().slice(2); + const tempPassword = Math.random().toString(36).slice(2,8) + Math.random().toString(36).toUpperCase().slice(2, 8); // 임시 비밀번호로 사용자 비밀번호 변경 await updatePassword(user.id, tempPassword);