Fixed default throttle class

This commit is contained in:
Spitap
2023-01-27 17:41:32 +01:00
parent 126f3a7ea5
commit bde07163b0
9 changed files with 44 additions and 33 deletions
+9 -4
View File
@@ -12,9 +12,10 @@ from drf_spectacular.utils import extend_schema
from rest_framework import response, status
from rest_framework_simplejwt import views as jwt_views
from rest_framework_simplejwt.exceptions import InvalidToken, TokenError
from rest_framework.throttling import ScopedRateThrottle
from rest_framework.views import APIView
from modoboa.lib.throttle import UserDosThrottle
from modoboa.lib.throttle import UserDosThrottleView
from modoboa.core.password_hashers import get_password_hasher
from modoboa.core.utils import check_for_updates
from modoboa.parameters import tools as param_tools
@@ -28,7 +29,8 @@ logger = logging.getLogger("modoboa.auth")
class TokenObtainPairView(jwt_views.TokenObtainPairView):
"""We overwrite this view to deal with password scheme update."""
throttle_classes = [ScopedRateThrottle]
throttle_scope = "login"
def post(self, request, *args, **kwargs):
@@ -87,7 +89,8 @@ class EmailPasswordResetView(APIView):
"""
An Api View which provides a method to request a password reset token based on an e-mail address.
"""
throttle_classes = [ScopedRateThrottle]
throttle_scope = 'password_recovery_request'
def post(self, request, *args, **kwargs):
@@ -126,6 +129,7 @@ class DefaultPasswordResetView(EmailPasswordResetView):
class PasswordResetSmsTOTP(APIView):
""" Check SMS Totp code. """
throttle_classes = [ScopedRateThrottle]
throttle_scope = 'password_recovery_totp_check'
def post(self, request, *args, **kwargs):
@@ -153,6 +157,7 @@ class PasswordResetSmsTOTP(APIView):
class PasswordResetConfirmView(APIView):
""" Get and set new user password. """
throttle_classes = [ScopedRateThrottle]
throttle_scope = 'password_recovery_apply'
def post(self, request, *args, **kwargs):
@@ -174,7 +179,7 @@ class PasswordResetConfirmView(APIView):
class ComponentsInformationAPIView(APIView):
"""Retrieve information about installed components."""
throttle_classes = [UserDosThrottle]
throttle_classes = [UserDosThrottleView]
@extend_schema(responses=serializers.ModoboaComponentSerializer(many=True))
def get(self, request, *args, **kwargs):