
    )Jf                         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d
S )    )local)get_user_model)ModelBackend   )app_settings)AuthenticationMethod)filter_users_by_emailfilter_users_by_usernamec                   R    e Zd Zd Zd Zd Zd Zed             Zed             Z	dS )AuthenticationBackendc                     d }t           j        t          j        k    r | j        di |}nDt           j        t          j        k    r | j        di |}|s | j        di |}n | j        di |}|S )N )r   AUTHENTICATION_METHODr   EMAIL_authenticate_by_emailUSERNAME_EMAIL_authenticate_by_username)selfrequestcredentialsrets       `/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/allauth/account/auth_backends.pyauthenticatez"AuthenticationBackend.authenticate   s    -1E1KKK-$-<<<<CC/3G3VVV-$-<<<<C D4d4CC{CC0$0??;??C
    c                    t           j        }|                    d          }|                    d          }t                      }|r||d S 	 t	          |                                          }|                     ||          r|S d S # |j        $ r-  t                                                      |           Y d S 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4
	+H5599;;D ##D(33     	 	 	 N++H55544		s   !B	 	3C ?C c                     |                     d|                     d                    }|r4t          |d          D ]"}|                     ||d                   r|c S #d S )Nemailr   T)prefer_verifiedr   )r   r	   r    )r   r   r'   r%   s       r   r   z,AuthenticationBackend._authenticate_by_email0   sw     )D)DEE 	 -eTJJJ    ''k*.EFF  KKK tr   c                     |                     |          }|r,|                     |          }|s|                     |           |S N)check_passworduser_can_authenticate_stash_user)r   r%   r   r   s       r   r    z%AuthenticationBackend._check_password=   sQ    !!(++ 	',,T22C '  &&&
r   c                 J    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                 ,    |                      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 5 5 5 5 5       . . . . . . B B B B B B B B 
U% U% U% U% U%L U% U% U% U% U%r   