a
    Sic†  ã                   @   sF   d dl mZ d dlmZ d dlmZmZ d dlmZ G dd„ dƒZ	dS )é    )ÚCallable)Úsettings)ÚHttpRequestÚHttpResponse)Úget_lockout_responsec                   @   s0   e Zd ZdZeddœdd„Zeedœdd„ZdS )	ÚAxesMiddlewareaà  
    Middleware that calculates necessary HTTP request attributes for attempt monitoring
    and maps lockout signals into readable HTTP 403 Forbidden responses.

    If a project uses ``django rest framework`` then the middleware updates the
    request and checks whether the limit has been exceeded. It's needed only
    for integration with DRF because it uses its own request object.

    This middleware recognizes a logout monitoring flag in the request and
    and uses the ``axes.helpers.get_lockout_response`` handler for returning
    customizable and context aware lockout message to the end user if necessary.

    To customize the lockout handling behaviour further, you can subclass this middleware
    and change the ``__call__`` method to your own liking.

    Please see the following configuration flags before customizing this handler:

    - ``AXES_LOCKOUT_TEMPLATE``,
    - ``AXES_LOCKOUT_URL``,
    - ``AXES_COOLOFF_MESSAGE``, and
    - ``AXES_PERMALOCK_MESSAGE``.
    N)Úget_responseÚreturnc                 C   s
   || _ d S )N)r   )Úselfr   © r   úK/var/www/html/django/DPS/env/lib/python3.9/site-packages/axes/middleware.pyÚ__init__!   s    zAxesMiddleware.__init__)Úrequestr	   c                 C   s6   |   |¡}tjr2t|dd ƒr2t|dd ƒ}t||ƒ}|S )NÚaxes_locked_outÚaxes_credentials)r   r   ÚAXES_ENABLEDÚgetattrr   )r
   r   ÚresponseÚcredentialsr   r   r   Ú__call__$   s    

zAxesMiddleware.__call__)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   	   s   r   N)
Útypingr   Údjango.confr   Údjango.httpr   r   Úaxes.helpersr   r   r   r   r   r   Ú<module>   s   