from ratelimitbackend.backends import RateLimitMixin
from django.conf import settings

if settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
    from edraak_ratelimit.backends import EdraakRateLimitMixin
    RateLimitMixin = EdraakRateLimitMixin


class BadRequestRateLimiter(RateLimitMixin):
    """
    Use the 3rd party RateLimitMixin to help do rate limiting on the Password Reset flows
    """

    def is_rate_limit_exceeded(self, request):
        """
        Returns if the client has been rated limited
        """
        counts = self.get_counters(request)
        is_exceeded = sum(counts.values()) >= self.requests

        if is_exceeded:
            self.db_log_failed_attempt(request)

        return is_exceeded

    def tick_bad_request_counter(self, request):
        """
        Ticks any counters used to compute when rate limt has been reached
        """
        self.cache_incr(self.get_cache_key(request))

from ratelimitbackend.backends import RateLimitMixin
from django.conf import settings

if settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
    from edraak_ratelimit.backends import EdraakRateLimitMixin
    RateLimitMixin = EdraakRateLimitMixin


class BadRequestRateLimiter(RateLimitMixin):
    """
    Use the 3rd party RateLimitMixin to help do rate limiting on the Password Reset flows
    """

    def is_rate_limit_exceeded(self, request):
        """
        Returns if the client has been rated limited
        """
        counts = self.get_counters(request)
        is_exceeded = sum(counts.values()) >= self.requests

        if is_exceeded and settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
            self.db_log_failed_attempt(request)

        return is_exceeded

    def tick_bad_request_counter(self, request):
        """
        Ticks any counters used to compute when rate limt has been reached
        """
        self.cache_incr(self.get_cache_key(request))

Fix object has no db_log_failed_attempt
Fix object has no db_log_failed_attempt

  from ratelimitbackend.backends import RateLimitMixin
  from django.conf import settings
  
  if settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
      from edraak_ratelimit.backends import EdraakRateLimitMixin
      RateLimitMixin = EdraakRateLimitMixin
  
  
  class BadRequestRateLimiter(RateLimitMixin):
      """
      Use the 3rd party RateLimitMixin to help do rate limiting on the Password Reset flows
      """
  
      def is_rate_limit_exceeded(self, request):
          """
          Returns if the client has been rated limited
          """
          counts = self.get_counters(request)
          is_exceeded = sum(counts.values()) >= self.requests
  
-         if is_exceeded:
+         if is_exceeded and settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
              self.db_log_failed_attempt(request)
  
          return is_exceeded
  
      def tick_bad_request_counter(self, request):
          """
          Ticks any counters used to compute when rate limt has been reached
          """
          self.cache_incr(self.get_cache_key(request))
  
Fix object has no db_log_failed_attempt
## Code Before:
from ratelimitbackend.backends import RateLimitMixin
from django.conf import settings

if settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
    from edraak_ratelimit.backends import EdraakRateLimitMixin
    RateLimitMixin = EdraakRateLimitMixin


class BadRequestRateLimiter(RateLimitMixin):
    """
    Use the 3rd party RateLimitMixin to help do rate limiting on the Password Reset flows
    """

    def is_rate_limit_exceeded(self, request):
        """
        Returns if the client has been rated limited
        """
        counts = self.get_counters(request)
        is_exceeded = sum(counts.values()) >= self.requests

        if is_exceeded:
            self.db_log_failed_attempt(request)

        return is_exceeded

    def tick_bad_request_counter(self, request):
        """
        Ticks any counters used to compute when rate limt has been reached
        """
        self.cache_incr(self.get_cache_key(request))

## Instruction:
Fix object has no db_log_failed_attempt
## Code After:
from ratelimitbackend.backends import RateLimitMixin
from django.conf import settings

if settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
    from edraak_ratelimit.backends import EdraakRateLimitMixin
    RateLimitMixin = EdraakRateLimitMixin


class BadRequestRateLimiter(RateLimitMixin):
    """
    Use the 3rd party RateLimitMixin to help do rate limiting on the Password Reset flows
    """

    def is_rate_limit_exceeded(self, request):
        """
        Returns if the client has been rated limited
        """
        counts = self.get_counters(request)
        is_exceeded = sum(counts.values()) >= self.requests

        if is_exceeded and settings.FEATURES.get('EDRAAK_RATELIMIT_APP', False):
            self.db_log_failed_attempt(request)

        return is_exceeded

    def tick_bad_request_counter(self, request):
        """
        Ticks any counters used to compute when rate limt has been reached
        """
        self.cache_incr(self.get_cache_key(request))
