From 7ad17c2203dd735d4fb41324be483a82bc8bdbd3 Mon Sep 17 00:00:00 2001 From: mingi Date: Fri, 23 May 2025 14:20:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=203=EB=B6=84=20=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/models.py | 2 +- accounts/views.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/accounts/models.py b/accounts/models.py index 25aca21..a934db4 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -68,5 +68,5 @@ def is_expired(self): 인증 코드의 유효기간을 체크합니다. (예: 1분) """ now = timezone.now() - expiration_time = self.created_at + timezone.timedelta(minutes=1) + expiration_time = self.created_at + timezone.timedelta(minutes=3) return now > expiration_time \ No newline at end of file diff --git a/accounts/views.py b/accounts/views.py index 3d336ae..5cfee8c 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -307,6 +307,19 @@ def send_sms(self, request): "data": [{"detail": "전화번호가 필요합니다."}] }, status=status.HTTP_400_BAD_REQUEST) + # Prevent requesting a new code within 1 minute of the last one + try: + last = SMSAuthenticate.objects.filter(user_phone=user_phone).latest('created_at') + if not last.is_expired(): + return Response({ + "status": "error", + "message": "문자인증 실패", + "code": 429, + "data": [{"detail": "인증 코드는 3분에 한 번만 요청할 수 있습니다."}] + }, status=status.HTTP_429_TOO_MANY_REQUESTS) + except SMSAuthenticate.DoesNotExist: + pass + # SMSAuthenticate 객체 생성 또는 업데이트 try: sms_token_key = os.getenv("SMS_TOKEN_KEY")