a
    Sic                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZmZmZmZ eeZG dd	 d	eeZd
S )    )	getLogger)Optional)import_string)now)settings)AxesBaseHandlerAbstractAxesHandlerAxesHandler)get_client_ip_addressget_client_user_agentget_client_path_infoget_client_http_accept
toggleablec                   @   sb  e Zd ZdZdZed)eedddZedddde	e
 e	e
 eedd	d
Zedde	e edddZedde	e edddZedde
e	e edddZedd Zed*e	e edddZed+e	e edddZed,e	e edddZeed-eddd Zeed!d" Zeed#d$ Zeed%d& Zeed'd( ZdS ).AxesProxyHandlera  
    Proxy interface for configurable Axes signal handler class.

    If you wish to implement a custom version of this handler,
    you can override the settings.AXES_HANDLER configuration string
    with a class that implements a compatible interface and methods.

    Defaults to using axes.handlers.proxy.AxesProxyHandler if not overridden.
    Refer to axes.handlers.proxy.AxesProxyHandler for default implementation.
    NF)forcereturnc                 C   s   |s
| j sttj | _ | j S )z
        Fetch and initialize configured handler implementation and memoize it to avoid reinitialization.

        This method is re-entrant and can be called multiple times from e.g. Django application loader.
        )implementationr   r   AXES_HANDLER)clsr    r   O/var/www/html/django/DPS/env/lib/python3.9/site-packages/axes/handlers/proxy.pyget_implementation%   s    
z#AxesProxyHandler.get_implementation
ip_addressusernameip_or_username)r   r   r   r   c                C   s   |   j|||dS )Nr   )r   reset_attempts)r   r   r   r   r   r   r   r   1   s    zAxesProxyHandler.reset_attemptsage_days)r   r   c                C   s   |   j|dS Nr   )r   
reset_logsr   r   r   r   r   r    =   s    zAxesProxyHandler.reset_logsc                C   s   |   j|dS r   )r   reset_failure_logsr!   r   r   r   r"   A   s    z#AxesProxyHandler.reset_failure_logs)limit)r   r#   r   c                C   s   |   j|dS )N)r   )r    remove_out_of_limit_failure_logs)r   r   r#   r   r   r   r$   E   s    z1AxesProxyHandler.remove_out_of_limit_failure_logsc                 C   sv   | du rt d dS t| dsrt| ds0d| _t | _t| | _t| | _	t
| | _t| | _d| _d| _d| _dS )z`
        Update request attributes before passing them into the selected handler class.
        NzVAXES: AxesProxyHandler.update_request can not set request attributes to a None requestaxes_updatedaxes_locked_outFT)logerrorhasattrr&   r   Zaxes_attempt_timer
   Zaxes_ip_addressr   Zaxes_user_agentr   Zaxes_path_infor   Zaxes_http_acceptZaxes_failures_since_startr%   Zaxes_credentials)requestr   r   r   update_requestM   s     





zAxesProxyHandler.update_request)credentialsr   c                 C   s   |  | |  ||S N)r+   r   	is_lockedr   r*   r,   r   r   r   r.   d   s    
zAxesProxyHandler.is_lockedc                 C   s   |  | |  ||S r-   )r+   r   
is_allowedr/   r   r   r   r0   i   s    
zAxesProxyHandler.is_allowedc                 C   s   |  | |  ||S r-   )r+   r   get_failuresr/   r   r   r   r1   n   s    
zAxesProxyHandler.get_failures)r,   c                 K   s$   |  | |  j|||fi |S r-   )r+   r   user_login_failed)r   senderr,   r*   kwargsr   r   r   r2   s   s    
z"AxesProxyHandler.user_login_failedc                 K   s$   |  | |  j|||fi |S r-   )r+   r   user_logged_inr   r3   r*   userr4   r   r   r   r5   {   s    
zAxesProxyHandler.user_logged_inc                 K   s$   |  | |  j|||fi |S r-   )r+   r   user_logged_outr6   r   r   r   r8      s    
z AxesProxyHandler.user_logged_outc                 K   s   |   j|fi |S r-   )r   post_save_access_attemptr   instancer4   r   r   r   r9      s    z)AxesProxyHandler.post_save_access_attemptc                 K   s   |   j|fi |S r-   )r   post_delete_access_attemptr:   r   r   r   r<      s    z+AxesProxyHandler.post_delete_access_attempt)F)N)N)N)N)__name__
__module____qualname____doc__r   classmethodboolr	   r   r   strintr   r    r"   r$   staticmethodr+   dictr.   r0   r1   r   r2   r5   r8   r9   r<   r   r   r   r   r      s^   
r   N)loggingr   typingr   django.utils.module_loadingr   django.utils.timezoner   	axes.confr   Zaxes.handlers.baser   r   r	   axes.helpersr
   r   r   r   r   r=   r'   r   r   r   r   r   <module>   s   