fix: review issues - add rate limiting for auth views, add __str__ to User model
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
from typing import Any
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
from rest_framework.decorators import api_view, permission_classes, throttle_classes
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.throttling import AnonRateThrottle
|
||||
|
||||
from accounts.serializers import LoginSerializer, RegisterSerializer, UserSerializer
|
||||
|
||||
|
||||
class AuthRateThrottle(AnonRateThrottle):
|
||||
scope = "auth"
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
@permission_classes([AllowAny])
|
||||
@throttle_classes([AuthRateThrottle])
|
||||
def register_view(request: Request) -> Response:
|
||||
"""Register a new user account."""
|
||||
serializer = RegisterSerializer(data=request.data)
|
||||
@@ -24,6 +30,7 @@ def register_view(request: Request) -> Response:
|
||||
|
||||
@api_view(["POST"])
|
||||
@permission_classes([AllowAny])
|
||||
@throttle_classes([AuthRateThrottle])
|
||||
def login_view(request: Request) -> Response:
|
||||
"""Authenticate a user and return JWT tokens."""
|
||||
serializer = LoginSerializer(
|
||||
|
||||
Reference in New Issue
Block a user