Files
shopship/apps/account/api/throttles.py
T
2026-08-24 15:54:08 +03:30

26 lines
897 B
Python

from rest_framework.throttling import SimpleRateThrottle
class PhoneRateThrottle(SimpleRateThrottle):
"""محدودیت درخواست OTP بر اساس شماره موبایل (نه IP) تا با یک شماره ثابت اسپم نشود"""
scope = "otp_send"
def get_cache_key(self, request, view):
phone = request.data.get("phone")
if not phone:
return None
return self.cache_format % {"scope": self.scope, "ident": phone}
class OTPVerifyThrottle(SimpleRateThrottle):
"""محدودیت تلاش برای تایید OTP بر اساس شماره موبایل، برای جلوگیری از brute force"""
scope = "otp_verify"
def get_cache_key(self, request, view):
phone = request.data.get("phone")
if not phone:
return None
return self.cache_format % {"scope": self.scope, "ident": phone}