
    Vvg                     L   d dl mZ d dlmZmZ 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mZ d dlmZ  ee          Zdd
ee         de
fdZ	 dd
edee         dee         fdZ	 dd
edee         dee         fdZdd
ee         defdZ	 dd
edee         defdZd	S )    )	getLogger)ListOptional)QuerySet)HttpRequest)datetimenow)settings)get_client_usernameget_client_parametersget_cool_off)AccessAttemptNrequestreturnc                     t          |           }|t          d          | j        }|t                      |z
  S ||z
  S )zG
    Get threshold for fetching access attempts from the database.
    NzTCool off threshold can not be calculated with settings.AXES_COOLOFF_TIME set to None)r   	TypeErroraxes_attempt_timer	   )r   cool_offattempt_times      J/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/axes/attempts.pyget_cool_off_thresholdr      sV    
 G$$Hb
 
 	
 ,Luux(""    credentialsc                 x    t          | |          }t          || j        | j        | |          }d |D             }|S )za
    Return a list querysets of AccessAttempts that match the given request and credentials.
    c                 :    g | ]}t          j        j        d i |S ) )r   objectsfilter).0filter_kwargss     r   
<listcomp>z(filter_user_attempts.<locals>.<listcomp>,   s<        	$55}55  r   )r   r   axes_ip_addressaxes_user_agent)r   r   usernamefilter_kwargs_listattempts_lists        r   filter_user_attemptsr'       sZ     #7K88H.')7+BG[  /  M r   c                     t          | |          }t          j        t                              d           |S t          |           t                              d           fd|D             S )zf
    Get list of querysets with valid user attempts that match the given request and credentials.
    NzZAXES: Getting all access attempts from database because no AXES_COOLOFF_TIME is configuredz4AXES: Getting access attempts that are newer than %sc                 <    g | ]}|                                S ))attempt_time__gte)r   )r   attempts	thresholds     r   r!   z%get_user_attempts.<locals>.<listcomp>D   s'    WWWXHOOiO88WWWr   )r'   r
   AXES_COOLOFF_TIMElogdebugr   )r   r   r&   r,   s      @r   get_user_attemptsr0   3   sz     )+>>M!)		h	
 	
 	
 &w//IIIDiPPPWWWWWWWWr   c                    t           j        t                              d           dS t	          |           }t
          j                            |                                          \  }}t          	                    d||           |S )z8
    Clean expired user attempts from the database.
    Nz[AXES: Skipping clean for expired access attempts because no AXES_COOLOFF_TIME is configuredr   )attempt_time__ltzQAXES: Cleaned up %s expired access attempts from database that were older than %s)
r
   r-   r.   r/   r   r   r   r   deleteinfo)r   r,   count_s       r   clean_expired_user_attemptsr7   G   s    
 !)		i	
 	
 	
 q&w//I$++Y+GGNNPPHE1HH[  
 Lr   c                     t          | |          }d}|D ]}|                                \  }}||z  }t                              d|           |S )zO
    Reset all user attempts that match the given request and credentials.
    r   z-AXES: Reset %s access attempts from database.)r'   r3   r.   r4   )r   r   r&   r5   r+   _countr6   s          r   reset_user_attemptsr:   \   s_     )+>>ME!  OO%%	HH<eDDDLr   )N)loggingr   typingr   r   django.db.modelsr   django.httpr   django.utils.timezoner   r	   	axes.confr
   axes.helpersr   r   r   axes.modelsr   __name__r.   r   dictr'   r0   intr7   r:   r   r   r   <module>rF      s         ! ! ! ! ! ! ! ! % % % % % % # # # # # # / / / / / / / /       Q Q Q Q Q Q Q Q Q Q % % % % % %i# #H[$9 #X # # # #$ 9= '/~	(^   ( 9=X XX'/~X	(^X X X X( +)> #    , 9= '/~     r   