
    hs%                     X   S SK r S SKrS SKJr  S SKJr  S SKJr  S SK	J
r
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Jr  SrSrSrSrS rS"S jrS r\" S5      S 5       rS r \" S5      S#S j5       r!\" S5      S#S j5       r"S#S jr#S#S jr$S r%S r&S r'S r(S r)S r*S  r+S! r,g)$    N)sync_to_async)apps)settings)ImproperlyConfiguredPermissionDenied)rotate_tokenconstant_time_compareimport_string)sensitive_variables   )user_logged_inuser_logged_outuser_login_failed_auth_user_id_auth_user_backend_auth_user_hashnextc                 "    [        U 5      " 5       $ Nr   )paths    N/var/www/html/env/lib/python3.13/site-packages/django/contrib/auth/__init__.pyload_backendr      s          c                     / n[         R                   H)  n[        U5      nUR                  U (       a  X24OU5        M+     U(       d  [	        S5      eU$ )Nz\No authentication backends have been defined. Does AUTHENTICATION_BACKENDS contain anything?)r   AUTHENTICATION_BACKENDSr   appendr   )return_tuplesbackendsbackend_pathbackends       r   _get_backendsr#      sR    H 88|,=/gN 9 "8
 	
 Or   c                      [        SS9$ )NFr   )r#    r   r   get_backendsr'   '   s    u--r   credentialsc                     [         R                  " S[         R                  5      nSnU  H  nUR                  U5      (       d  M  X U'   M!     U $ )z
Clean a dictionary of credentials of potentially sensitive info before
sending to less secure functions.

Not comprehensive - intended for user_login_failed signal
z'api|token|key|secret|password|signaturez********************)recompileIsearch)r(   SENSITIVE_CREDENTIALSCLEANSED_SUBSTITUTEkeys       r   _clean_credentialsr1   +   sN     JJ'PRTRVRVW0 '',,2  r   c                 ~    [        5       R                  R                  R                  U R                  [
           5      $ r   )get_user_model_metapk	to_pythonsessionSESSION_KEYrequests    r   _get_user_session_keyr;   ;   s-     !!$$..w{/KLLr   c                 ^   [        SS9 HZ  u  p#[        R                  " UR                  5      n UR                  " U 40 UD6   UR                  " U 40 UD6nUc  MR  X5l        Us  $    [        R                  " [        [        U5      U S9  g! [
         a     M  f = f! [         a       MC  f = f)z;
If the given credentials are valid, return a User object.
Tr%   N)senderr(   r:   )r#   inspect	signatureauthenticatebind	TypeErrorr   r"   r   send__name__r1   )r:   r(   r"   r!   backend_signatureusers         r   r@   r@   A   s    
 "/T!B#--g.B.BC	""7:k:
	''?;?D
 <#% "C* %7%Dg#  	 	   	 	s#   BB
BB
B,+B,c                 J   #    [        [        5      " U 40 UD6I Sh  vN $  N7f)zSee authenticate().N)r   r@   )r:   r(   s     r   aauthenticaterH   `   s"      |,WDDDDD   #!#c                    SnUc  U R                   n[        US5      (       a  UR                  5       n[        U R                  ;   aj  [        U 5      UR                  :w  d6  U(       aI  [        U R                  R                  [        S5      U5      (       d  U R                  R                  5         OU R                  R                  5          U=(       d    UR                  n[        U[        5      (       d  [        SU-  5      e UR(                  R                  R+                  U5      U R                  [        '   X R                  [,        '   X0R                  [        '   [        U S
5      (       a  Xl         [/        U 5        [0        R2                  " UR4                  XS9  g! [          a-    [#        SS9n[%        U5      S:X  a	  US   u  pR N['        S	5      ef = f)z
Persist a user id and a backend in the request. This way a user doesn't
have to reauthenticate on every request. Note that data set during
the anonymous session is retained when the user logs in.
 Nget_session_auth_hashz5backend must be a dotted import path string (got %r).Tr%   r   r   zYou have multiple authentication backends configured and therefore must provide the `backend` argument or set the `backend` attribute on the user.rF   r=   r:   rF   )rF   hasattrrL   r8   r7   r;   r5   r
   getHASH_SESSION_KEYflush	cycle_keyr"   
isinstancestrrB   AttributeErrorr#   len
ValueErrorr4   value_to_stringBACKEND_SESSION_KEYr   r   rC   	__class__)r:   rF   r"   session_auth_hashr    _s         r   loginr]   f   s    |||t,-- 668goo% )TWW4)##$4b9;L  OO!!#!!#)T\\ '3''G'Q  (
 $(::==#@#@#FGOOK +2OO'((9OO$%wt~~wJ-  	 t4x=A!!JAw3 	s   F! !)GGc                 J   #    [        [        5      " XU5      I Sh  vN $  N7f)zSee login().N)r   r]   )r:   rF   r"   s      r   aloginr_      s     u%gW====rI   c                     [        U SS5      n[        USS5      (       d  Sn[        R                  " UR                  XS9  U R                  R                  5         [        U S5      (       a  SSKJn  U" 5       U l	        gg)zS
Remove the authenticated user's ID from the request and flush their session
data.
rF   Nis_authenticatedTrM   r   AnonymousUser)
getattrr   rC   rZ   r7   rQ   rN   django.contrib.auth.modelsrc   rF   )r:   rF   rc   s      r   logoutrf      si     7FD)D4+T22KOOw<$  r   c                 H   #    [        [        5      " U 5      I Sh  vN $  N7f)zSee logout().N)r   rf   r9   s    r   alogoutrh      s     v&w////   " "c                       [         R                  " [        R                  SS9$ ! [         a    [        S5      e[         a    [        S[        R                  -  5      ef = f)z7
Return the User model that is active in this project.
F)require_readyz:AUTH_USER_MODEL must be of the form 'app_label.model_name'z@AUTH_USER_MODEL refers to model '%s' that has not been installed)django_apps	get_modelr   AUTH_USER_MODELrW   r   LookupErrorr&   r   r   r3   r3      sg    

$$X%=%=USS 
"H
 	
  
"N&&'
 	

s	   "% ;A c                   ^ SSK Jn  Sn [        U 5      nU R                  [           nU[
        R                  ;   a  [        U5      nUR                  U5      n[        US5      (       a  U R                  R                  [        5      mT(       d  SnOUR                  5       n[        TU5      nU(       dy  T(       aV  [        U4S jUR                  5        5       5      (       a.  U R                  R!                  5         WU R                  [        '   OU R                  R#                  5         SnU=(       d    U" 5       $ ! [$         a     Nf = f)z
Return the user model instance associated with the given request session.
If no user is retrieved, return an instance of `AnonymousUser`.
r   rb   NrL   Fc              3   <   >#    U  H  n[        TU5      v   M     g 7fr   r	   ).0fallback_auth_hashsession_hashs     r   	<genexpr>get_user.<locals>.<genexpr>   s$      ,2W. .l<NOO2Ws   )modelsrc   r;   r7   rY   r   r   r   get_userrN   rO   rP   rL   r
   anyget_session_auth_fallback_hashrR   rQ   KeyError)	r:   rc   rF   user_idr!   r"   session_hash_verifiedr[   rt   s	           @r   rx   rx      s$   
 &D$'0':; 8;;;"<0G##G,Dt455&223CD#,1)(,(B(B(D%,A$&7-) - $ ,262U2U2W, ) )  113<M(89--/#"=?"=  s   D? ?
EEc                 H   #    [        [        5      " U 5      I Sh  vN $  N7f)zSee get_user().N)r   rx   r9   s    r   	aget_userr      s     x(1111ri   c                 (    U < SUR                   < 3$ )zA
Return the codename of the permission for the specified action.
r\   )
model_name)actionoptss     r   get_permission_codenamer      s     doo..r   c                     U R                   R                  5         [        US5      (       a3  U R                  U:X  a"  UR	                  5       U R                   [
        '   ggg)a/  
Updating a user's password logs out all sessions for the user.

Take the current request and the updated user object from which the new
session hash will be derived and update the session hash appropriately to
prevent a password change from logging out the session from which the
password was changed.
rL   N)r7   rR   rN   rF   rL   rP   r:   rF   s     r   update_session_auth_hashr      sN     OOt,--',,$2F,0,F,F,H() 3G-r   c                 
  #    U R                   R                  5       I Sh  vN   [        US5      (       aH  U R                  U:X  a7  U R                   R	                  [
        UR                  5       5      I Sh  vN   ggg N^ N	7f)zSee update_session_auth_hash().NrL   )r7   
acycle_keyrN   rF   asetrP   rL   r   s     r   aupdate_session_auth_hashr     si     
//
$
$
&&&t,--',,$2Foo""#3T5O5O5QRRR 3G- 'Rs"   BA?AB7B8BB)Fr   )-r>   r*   asgiref.syncr   django.appsr   rl   django.confr   django.core.exceptionsr   r   django.middleware.csrfr   django.utils.cryptor
   django.utils.module_loadingr   django.views.decorators.debugr   signalsr   r   r   r8   rY   rP   REDIRECT_FIELD_NAMEr   r#   r'   r1   r;   r@   rH   r]   r_   rf   rh   r3   rx   r   r   r   r   r&   r   r   <module>r      s     	 & +   I / 5 5 = G G* $  !
. ]# $M ]# $< ]#E $E
2Kj>
'$0

")#X2
/ISr   