48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
from rest_framework.throttling import SimpleRateThrottle
|
|
|
|
|
|
class RequestOTPDayRateThrottle(SimpleRateThrottle):
|
|
scope = 'otp_day'
|
|
|
|
def get_cache_key(self, request, view):
|
|
if request.user and request.user.is_authenticated:
|
|
ident = request.user.pk
|
|
else:
|
|
ident = self.get_ident(request)
|
|
|
|
return self.cache_format % {
|
|
'scope': self.scope,
|
|
'ident': ident
|
|
}
|
|
|
|
|
|
|
|
class RequestOTPMinRateThrottle(RequestOTPDayRateThrottle):
|
|
scope = 'otp_min'
|
|
|
|
|
|
class NumberedRequestOTPDayRateThrottle(SimpleRateThrottle):
|
|
scope = 'numbered_otp_day'
|
|
|
|
def get_ident(self, request):
|
|
return request.data.get('phone_number')
|
|
|
|
def get_cache_key(self, request, view):
|
|
if request.user and request.user.is_authenticated:
|
|
ident = request.user.pk
|
|
else:
|
|
ident = self.get_ident(request)
|
|
|
|
return self.cache_format % {
|
|
'scope': self.scope,
|
|
'ident': ident
|
|
}
|
|
|
|
|
|
|
|
class NumberedRequestOTPMinRateThrottle(NumberedRequestOTPDayRateThrottle):
|
|
scope = 'numbered_otp_min'
|
|
|
|
|
|
|
|
|