
    f                     t    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  e       a G d d	e      Zy
)    )local)get_user_model)ModelBackend   )app_settings)AuthenticationMethod)filter_users_by_emailfilter_users_by_usernamec                   D    e Zd Zd Zd Zd Zd Zed        Zed        Z	y)AuthenticationBackendc                 *   d }t         j                  t        j                  k(  r | j                  di |}|S t         j                  t        j
                  k(  r( | j                  di |}|s | j                  di |}|S  | j                  di |}|S )N )r   AUTHENTICATION_METHODr   EMAIL_authenticate_by_emailUSERNAME_EMAIL_authenticate_by_username)selfrequestcredentialsrets       X/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/account/auth_backends.pyauthenticatez"AuthenticationBackend.authenticate   s    --1E1K1KK-$--<<C 
 //3G3V3VV-$--<<C4d44C{C 
 1$00?;?C
    c                 L   t         j                  }|j                  d      }|j                  d      }t               }|r||y 	 t	        |      j                         }| j                  ||      r|S y # |j                  $ r!  t                      j                  |       Y y w xY w)Nusernamepassword)r   USER_MODEL_USERNAME_FIELDgetr   r
   _check_passwordDoesNotExistset_password)r   r   username_fieldr   r   Userusers          r   r   z/AuthenticationBackend._authenticate_by_username   s    %????:.??:.!1X5E
	+H599;D ##D(3 4    	 N++H5		s   A3 3-B#"B#c                     |j                  d|j                  d            }|r+t        |d      D ]  }| j                  ||d         s|c S  y )Nemailr   T)prefer_verifiedr   )r   r	   r    )r   r   r'   r%   s       r   r   z,AuthenticationBackend._authenticate_by_email0   sU     )DE-eTJ  ''k*.EFK  r   c                 t    |j                  |      }|r$| j                  |      }|s| j                  |       |S N)check_passworduser_can_authenticate_stash_user)r   r%   r   r   s       r   r    z%AuthenticationBackend._check_password=   s;    !!(+,,T2C  &
r   c                 >    t        t        dd      }|t        _        |S )a  Now, be aware, the following is quite ugly, let me explain:

        Even if the user credentials match, the authentication can fail because
        Django's default ModelBackend calls user_can_authenticate(), which
        checks `is_active`. Now, earlier versions of allauth did not do this
        and simply returned the user as authenticated, even in case of
        `is_active=False`. For allauth scope, this does not pose a problem, as
        these users are properly redirected to an account inactive page.

        This does pose a problem when the allauth backend is used in a
        different context where allauth is not responsible for the login. Then,
        by not checking on `user_can_authenticate()` users will allow to become
        authenticated whereas according to Django logic this should not be
        allowed.

        In order to preserve the allauth behavior while respecting Django's
        logic, we stash a user for which the password check succeeded but
        `user_can_authenticate()` failed. In the allauth authentication logic,
        we can then unstash this user and proceed pointing the user to the
        account inactive page.
        r%   N)getattr_stashr%   )clsr%   r   s      r   r-   z!AuthenticationBackend._stash_userE   s    0 ffd+
r   c                 $    | j                  d       S r*   )r-   )r1   s    r   unstash_authenticated_userz0AuthenticationBackend.unstash_authenticated_usera   s    t$$r   N)
__name__
__module____qualname__r   r   r   r    classmethodr-   r3   r   r   r   r   r      s>    
*  6 % %r   r   N)	threadingr   django.contrib.authr   django.contrib.auth.backendsr    r   r   utilsr	   r
   r0   r   r   r   r   <module>r=      s.     . 5  . B 
U%L U%r   