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);