Skip to content

Commit

Permalink
[fix] 전화번호 중복 제한, 임시 비밀번호 12자리로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuunyeok committed Feb 19, 2024
1 parent 9e24769 commit fcaa4b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/controllers/sms.controller.js
Original file line number Diff line number Diff line change
@@ -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자리

Expand Down
6 changes: 6 additions & 0 deletions src/models/sms.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
2 changes: 1 addition & 1 deletion src/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit fcaa4b9

Please sign in to comment.