a
    Sic  ã                   @   sŠ   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZmZmZ G dd	„ d	eƒZG d
d„ deeƒZdS )é    )ÚOptional)Úsettings)ÚBaseBackendÚModelBackend)ÚHttpRequest)ÚAxesBackendPermissionDeniedÚ#AxesBackendRequestParameterRequired)ÚAxesProxyHandler)Úget_credentialsÚget_lockout_messageÚ
toggleablec                   @   s2   e Zd ZdZedeee ee edœdd„ƒZ	dS )ÚAxesStandaloneBackenda   
    Authentication backend class that forbids login attempts for locked out users.

    Use this class as the first item of ``AUTHENTICATION_BACKENDS`` to
    prevent locked out users from being logged in by the Django authentication flow.

    .. note:: This backend does not log your user in. It monitors login attempts.
              It also does not run any permissions checks at all.
              Authentication is handled by the following backends that are configured in ``AUTHENTICATION_BACKENDS``.
    N)ÚrequestÚusernameÚpasswordÚkwargsc                 K   sf   |du rt dƒ‚tf ||dœ|¤Ž}t ||¡r4dS tƒ }| di ¡}||d< tjsZd|_t	dƒ‚dS )a  
        Checks user lockout status and raises an exception if user is not allowed to log in.

        This method interrupts the login flow and inserts  error message directly to the
        ``response_context`` attribute that is supplied as a keyword argument.

        :keyword response_context: kwarg that will be have its ``error`` attribute updated with context.
        :raises AxesBackendRequestParameterRequired: if request parameter is not passed.
        :raises AxesBackendPermissionDenied: if user is already locked out.
        Nz=AxesBackend requires a request as an argument to authenticate)r   r   Úresponse_contextÚerrorTz6AxesBackend detected that the given user is locked out)
r   r
   r	   Z
is_allowedr   Úgetr   Ú-AXES_RESET_COOL_OFF_ON_FAILURE_DURING_LOCKOUTZaxes_locked_outr   )Úselfr   r   r   r   ÚcredentialsÚ	error_msgr   © r   úI/var/www/html/django/DPS/env/lib/python3.9/site-packages/axes/backends.pyÚauthenticate   s    ÿÿz"AxesStandaloneBackend.authenticate)NN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   ÚstrÚdictr   r   r   r   r   r      s     üûr   c                   @   s   e Zd ZdZdS )ÚAxesBackenda  
    Axes authentication backend that also inherits from ModelBackend,
    and thus also performs other functions of ModelBackend such as permissions checks.

    Use this class as the first item of ``AUTHENTICATION_BACKENDS`` to
    prevent locked out users from being logged in by the Django authentication flow.

    .. note:: This backend does not log your user in. It monitors login attempts.
              Authentication is handled by the following backends that are configured in ``AUTHENTICATION_BACKENDS``.
    N)r   r   r   r   r   r   r   r   r"   M   s   r"   N)Útypingr   Údjango.confr   Zdjango.contrib.auth.backendsr   r   Údjango.httpr   Zaxes.exceptionsr   r   Zaxes.handlers.proxyr	   Zaxes.helpersr
   r   r   r   r"   r   r   r   r   Ú<module>   s   ?