
    Sњh`                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  SSK
Jr  SSKJrJr  \" 5       q " S	 S
\5      rg)    )local)get_user_model)ModelBackend)get_adapter)LoginMethod   )app_settings)filter_users_by_emailfilter_users_by_usernamec                       \ rS rSrS rS rS\S\4S jrS\S\4S jrS	\S\4S
 jr	S r
S r\S 5       r\S 5       rSrg)AuthenticationBackend   c                     UR                  S5      nU(       d  g SU l        U R                  " U40 UD6nU R                  (       d  U R                  U5        U$ )NpasswordF)get_did_check_password_authenticate_mitigate_timing_attack)selfrequestcredentialsr   users        XD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\allauth/account/auth_backends.pyauthenticate"AuthenticationBackend.authenticate   sO    ??:.#( !!'9[9''((2    c                    UR                  S5      nUR                  S5      nU(       aV  [        R                  [        R                  ;   a  U R                  XC5      nU(       a  U$ U R                  XC5      nU(       a  U$ UR                  S5      nU(       a  U R                  Xc5      nU(       a  U$ UR                  S5      nU(       a  U R                  Xs5      nU(       a  U$ g )Nr   usernameemailphone)r   r   EMAILr	   LOGIN_METHODS_authenticate_by_email_authenticate_by_username_authenticate_by_phone)r   r   r   r   r   r   r   r    s           r   r   #AuthenticationBackend._authenticate   s    ??:.??:.  L$>$>> 228FK11(ED(..u?D(..u?Dr   r    r   c                     U(       a"  [         R                  [        R                  ;  a  g [	        5       nUR                  U5      nU R                  XB5      $ N)r   PHONEr	   r"   r   get_user_by_phone_check_password)r   r    r   adapterr   s        r   r%   ,AuthenticationBackend._authenticate_by_phone9   sC    ))1K1KK-((/##D33r   r   c                     [         R                  [        R                  ;  d  [        R                  (       a  U(       d  g [        U5      R                  5       nU R                  X25      $ r(   )r   USERNAMEr	   r"   USER_MODEL_USERNAME_FIELDr   firstr+   )r   r   r   r   s       r   r$   /AuthenticationBackend._authenticate_by_username@   sI    !!)C)CC ::'1779##D33r   r   c                     U(       a"  [         R                  [        R                  ;  a  g [	        USS9nU H  nU R                  XB5      (       d  M  Us  $    g )NT)prefer_verified)r   r!   r	   r"   r
   r+   )r   r   r   usersr   s        r   r#   ,AuthenticationBackend._authenticate_by_emailJ   sN    
 ))1K1KK%eTBD##D33  r   c                 @    [        5       " 5       R                  U5        g r(   )r   set_password)r   r   s     r   r   -AuthenticationBackend._mitigate_timing_attackW   s    ''1r   c                     U(       d  g SU l         UR                  U5      nU(       a)  U R                  U5      nU(       d  U R                  U5        U(       a  U$ S $ )NT)r   check_passworduser_can_authenticate_stash_user)r   r   r   oks       r   r+   %AuthenticationBackend._check_passwordZ   sQ    #'   *++D1B  &t#t#r   c                 >    [        [        SS5      nU[        l        U$ )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   rets      r   r=   !AuthenticationBackend._stash_usere   s    0 ffd+
r   c                 $    U R                  S 5      $ r(   )r=   )rC   s    r   unstash_authenticated_user0AuthenticationBackend.unstash_authenticated_user   s    t$$r   )r   N)__name__
__module____qualname____firstlineno__r   r   strr%   r$   r#   r   r+   classmethodr=   rG   __static_attributes__ r   r   r   r      s{    <4C 43 44# 4 4 2	$  6 % %r   r   N)	threadingr   django.contrib.authr   django.contrib.auth.backendsr   allauth.account.adapterr   allauth.account.app_settingsr    r	   utilsr
   r   rB   r   rP   r   r   <module>rX      s1     . 5 / 4  B 
s%L s%r   