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}