iMerica / dj-rest-auth

Authentication for Django Rest Framework
https://dj-rest-auth.readthedocs.io/en/latest/index.html
MIT License
1.63k stars 304 forks source link

AllAuth rate limits are not respected in Resend Email Verification #497

Closed mustansirgodhrawala closed 1 year ago

mustansirgodhrawala commented 1 year ago

Problem

Django allauth rate limit using the setting variable below did not work for me. I do not know if this is a bug, or something else altogether or whether it's been referenced before. For anyone looking to make something like this work with dj_rest_auth in its current state they can implement some as I've done.

ACCOUNT_EMAIL_CONFIRMATION_COOLDOWN=180

My Solution

  1. I added the following to urls.py overriding the default resend email verification view.

    path('registration/resend-email/', CustomResendEmailVerificationView.as_view(), name='account_email_verification_sent'),
  2. I create the following view in one of my apps as such and import it into the urls.py above

    
    from rest_framework.throttling import UserRateThrottle, AnonRateThrottle
    from dj_rest_auth.registration.views import ResendEmailVerificationView

class CustomResendEmailVerificationThrottle(UserRateThrottle, AnonRateThrottle): rate = '24/day'

class CustomResendEmailVerificationView(ResendEmailVerificationView): throttle_classes = [CustomResendEmailVerificationThrottle]



I've created a custom throttle class above using Django-rest-framework that works for both authenticated and unauthenticated users. 

**Please let me know if this is a bug as I would love to contribute and submit a pull request for this with everyone's support**
iMerica commented 1 year ago

Nice solution. I'm going to close this because this package does not intend to support every possible feature of all-auth.

All-auth is only connected to this repo through an optional dependency for registration and it causes more problems than it solves.