Ë
    ûûàgR  ã                   ó€   — 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 ddlmZmZ  e«       a G d	„ d
e«      Zy)é    )Úlocal)Úget_user_model)ÚModelBackend)Úget_adapter)ÚLoginMethodé   )Úapp_settings)Úfilter_users_by_emailÚfilter_users_by_usernamec                   ót   — e Zd Zd„ Zd„ Zdedefd„Zdedefd„Zdedefd	„Zd
„ Z	d„ Z
ed„ «       Zed„ «       Zy)ÚAuthenticationBackendc                 óœ   — |j                  d«      }|sy d| _         | j                  |fi |¤Ž}| j                  s| j                  |«       |S )NÚpasswordF)ÚgetÚ_did_check_passwordÚ_authenticateÚ_mitigate_timing_attack)ÚselfÚrequestÚcredentialsr   Úusers        ú[/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/allauth/account/auth_backends.pyÚauthenticatez"AuthenticationBackend.authenticate   sQ   € Ø—?‘? :Ó.ˆÙØØ#(ˆÔ Ø!ˆt×!Ñ! 'Ñ9¨[Ñ9ˆØ×'Ò'Ø×(Ñ(¨Ô2Øˆó    c                 óˆ  — |j                  d«      }|j                  d«      }|rLt        j                  t        j                  v r| j                  ||«      }|r|S | j                  ||«      }|r|S |j                  d«      }|r| j                  ||«      }|r|S |j                  d«      }|r| j                  ||«      }|r|S y )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   z#AuthenticationBackend._authenticate   sÄ   € Ø—?‘? :Ó.ˆØ—?‘? :Ó.ˆÙÜ× Ñ ¤L×$>Ñ$>Ñ>ð ×2Ñ2°8¸XÓF�ÙØ�KØ×1Ñ1°(¸HÓEˆDÙØ�à—‘ Ó(ˆÙØ×.Ñ.¨u°hÓ?ˆDÙØ�à—‘ Ó(ˆÙØ×.Ñ.¨u°hÓ?ˆDÙØ�Ør   r   r   c                 ó¢   — |r t         j                  t        j                  vry t	        «       }|j                  |«      }| j                  ||«      S ©N)r   ÚPHONEr	   r    r   Úget_user_by_phoneÚ_check_password)r   r   r   Úadapterr   s        r   r#   z,AuthenticationBackend._authenticate_by_phone9   sE   € Ùœ×)Ñ)´×1KÑ1KÑKØÜ“-ˆØ×(Ñ(¨Ó/ˆØ×#Ñ# D¨(Ó3Ð3r   r   c                 ó¾   — t         j                  t        j                  vst        j                  r|sy t        |«      j                  «       }| j                  ||«      S r%   )r   ÚUSERNAMEr	   r    ÚUSER_MODEL_USERNAME_FIELDr   Úfirstr(   )r   r   r   r   s       r   r"   z/AuthenticationBackend._authenticate_by_username@   sK   € ä×!Ñ!¬×)CÑ)CÑCÜ ×:Ò:ÙàÜ'¨Ó1×7Ñ7Ó9ˆØ×#Ñ# D¨(Ó3Ð3r   r   c                 óž   — |r t         j                  t        j                  vry t	        |d¬«      }|D ]  }| j                  ||«      sŒ|c S  y )NT)Úprefer_verified)r   r   r	   r    r
   r(   )r   r   r   Úusersr   s        r   r!   z,AuthenticationBackend._authenticate_by_emailJ   sR   € ñ
 œ×)Ñ)´×1KÑ1KÑKØÜ% e¸TÔBˆØò 	ˆDØ×#Ñ# D¨(Õ3Ø’ð	ð r   c                 ó@   —  t        «       «       j                  |«       y r%   )r   Úset_password)r   r   s     r   r   z-AuthenticationBackend._mitigate_timing_attackW   s   € ØŒÓÓ×'Ñ'¨Õ1r   c                 ó�   — |sy d| _         |j                  |«      }|r$| j                  |«      }|s| j                  |«       |r|S d S )NT)r   Úcheck_passwordÚuser_can_authenticateÚ_stash_user)r   r   r   Úoks       r   r(   z%AuthenticationBackend._check_passwordZ   sQ   € ÙØØ#'ˆÔ Ø× Ñ  Ó*ˆÙØ×+Ñ+¨DÓ1ˆBÙØ× Ñ  Ô&ÙˆtÐ#˜tÐ#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   Úrets      r   r6   z!AuthenticationBackend._stash_usere   s   € ô0 ”f˜f dÓ+ˆØŒŒØˆ
r   c                 ó$   — | j                  d «      S r%   )r6   )r;   s    r   Úunstash_authenticated_userz0AuthenticationBackend.unstash_authenticated_user�   s   € à�‰˜tÓ$Ð$r   N)Ú__name__Ú
__module__Ú__qualname__r   r   Ústrr#   r"   r!   r   r(   Úclassmethodr6   r>   © r   r   r   r      s{   „ òòð<4¨Cð 4¸3ó 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   r:   r   rD   r   r   ú<module>rL      s1   ðÝ å .Ý 5å /Ý 4å ß Bñ 
‹€ôs%˜Lõ s%r   