24 lines
805 B
Python
24 lines
805 B
Python
from rest_framework.throttling import SimpleRateThrottle
|
|
|
|
|
|
class OTPSendByPhoneThrottle(SimpleRateThrottle):
|
|
"""Per-phone hourly limit on OTP sends (configured via DEFAULT_THROTTLE_RATES)."""
|
|
|
|
scope = "otp_send_phone"
|
|
|
|
def get_cache_key(self, request, view):
|
|
phone = (request.data or {}).get("phone_number") if hasattr(request, "data") else None
|
|
if not phone:
|
|
return None
|
|
return self.cache_format % {"scope": self.scope, "ident": phone}
|
|
|
|
|
|
class OTPSendByIPThrottle(SimpleRateThrottle):
|
|
"""Per-IP throttle on OTP sends to absorb scripted abuse from a single client."""
|
|
|
|
scope = "otp_send_ip"
|
|
|
|
def get_cache_key(self, request, view):
|
|
ident = self.get_ident(request)
|
|
return self.cache_format % {"scope": self.scope, "ident": ident}
|