
    hh.                        S SK r S SKJr  S SKJr  S SKJrJr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  S SKJr  S rS r " S S\5      r " S S\5      r  " S S5      r! " S S\!5      r"g)    N)partial)urlsplit)iscoroutinefunctionmarkcoroutinefunctionsync_to_async)settings)auth)REDIRECT_FIELD_NAMEload_backend)RemoteUserBackend)redirect_to_login)ImproperlyConfigured)resolve_url)MiddlewareMixinRemovedInDjango61Warning)SimpleLazyObjectc                 r    [        U S5      (       d  [        R                  " U 5      U l        U R                  $ )N_cached_user)hasattrr	   get_userr   requests    YD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\django/contrib/auth/middleware.pyr   r      s,    7N++#}}W5    c                    #    [        U S5      (       d#  [        R                  " U 5      I S h  vN U l        U R                  $  N7f)N_acached_user)r   r	   	aget_userr   r   s    r   auserr      s7     7O,,&*nnW&= =    !>s   +AAAc                       \ rS rSrS rSrg)AuthenticationMiddleware   c                    ^ [        TS5      (       d  [        S5      e[        U4S j5      Tl        [	        [
        T5      Tl        g )NsessionzThe Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE setting to insert 'django.contrib.sessions.middleware.SessionMiddleware' before 'django.contrib.auth.middleware.AuthenticationMiddleware'.c                     > [        T 5      $ N)r   r   s   r   <lambda>:AuthenticationMiddleware.process_request.<locals>.<lambda>(   s
    0Ar   )r   r   r   userr   r   selfr   s    `r   process_request(AuthenticationMiddleware.process_request   s@    w	**&M  ((ABw/r    N)__name__
__module____qualname____firstlineno__r+   __static_attributes__r-   r   r   r    r       s    
0r   r    c                   4    \ rS rSrSr\rS rS rS r	S r
Srg)	LoginRequiredMiddleware,   z
Middleware that redirects all unauthenticated requests to a login page.

Views using the login_not_required decorator will not be redirected.
c                     UR                   R                  (       a  g [        USS5      (       d  g U R                  X5      $ )Nlogin_requiredT)r(   is_authenticatedgetattrhandle_no_permission)r*   r   	view_func	view_argsview_kwargss        r   process_view$LoginRequiredMiddleware.process_view5   s6    <<((y"2D99((<<r   c                     [        USS 5      =(       d    [        R                  nU(       d  [        S5      e[	        U5      $ )N	login_urlzNo login URL to redirect to. Define settings.LOGIN_URL or provide a login_url via the 'django.contrib.auth.decorators.login_required' decorator.)r9   r   	LOGIN_URLr   str)r*   r;   rA   s      r   get_login_url%LoginRequiredMiddleware.get_login_url>   s<    I{D9OX=O=O	&- 
 9~r   c                 0    [        USU R                  5      $ )Nredirect_field_name)r9   rG   )r*   r;   s     r   get_redirect_field_name/LoginRequiredMiddleware.get_redirect_field_nameH   s    y"79Q9QRRr   c                    UR                  5       n[        U R                  U5      5      n[        U5      S S u  pV[        U5      S S u  pxU(       a  XW:X  a  U(       a  Xh:X  a  UR	                  5       n[        UUU R                  U5      5      $ )N   )build_absolute_urir   rD   r   get_full_pathr   rH   )	r*   r   r;   pathresolved_login_urllogin_schemelogin_netloccurrent_schemecurrent_netlocs	            r   r:   ,LoginRequiredMiddleware.handle_no_permissionK   s    ))+(););I)FG &..@%A"1%E")1$);& > >((*D ((3
 	
r   r-   N)r.   r/   r0   r1   __doc__r
   rG   r>   rD   rH   r:   r2   r-   r   r   r4   r4   ,   s$     .=S
r   r4   c                   f   ^  \ rS rSrSrSrSrU 4S jrSrSr	S r
S rS rS	 rS
 rS rS rSrU =r$ )RemoteUserMiddleware^   aS  
Middleware for utilizing web-server-provided authentication.

If request.user is not authenticated, then this middleware attempts to
authenticate the username from the ``REMOTE_USER`` key in ``request.META``,
an environment variable commonly set by the webserver.

If authentication is successful, the user is automatically logged in to
persist the user in the session.

The ``request.META`` key is configurable and defaults to ``REMOTE_USER``.
Subclass this class and change the ``header`` attribute if you need to
use a different key from ``request.META``, for example a HTTP request
header.
Tc                    > Uc  [        S5      eXl        [        U5      U l        U R                  (       a  [	        U 5        [
        TU ]  5         g )Nzget_response must be provided.)
ValueErrorget_responser   is_asyncr   super__init__)r*   r[   	__class__s     r   r^   RemoteUserMiddleware.__init__r   sA    =>>(+L9==!$'r   REMOTE_USERc                     U R                   (       a  U R                  U5      $ U R                  U5        U R                  U5      $ r%   )r\   	__acall__r+   r[   r)   s     r   __call__RemoteUserMiddleware.__call__   s7    ==>>'**W%  ))r   c                 .   [        US5      (       d  [        S5      e UR                  U R                     nUR                  R                  (       a?  UR                  R                  5       U R                  X!5      :X  a  g U R                  U5        [        R                  " XS9nU(       a  X1l        [        R                  " X5        g g ! [         a@    U R
                  (       a,  UR                  R                  (       a  U R                  U5         g f = f)Nr(   The Django remote user auth middleware requires the authentication middleware to be installed.  Edit your MIDDLEWARE setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the RemoteUserMiddleware class.remote_user)r   r   METAheaderKeyErrorforce_logout_if_no_headerr(   r8   _remove_invalid_userget_usernameclean_usernamer	   authenticateloginr*   r   usernamer(   s       r   r+   $RemoteUserMiddleware.process_request   s    w''&: 	||DKK0H <<((||((*d.A.A(.TT ))'2   ?  LJJw%	 +  	 --',,2O2O))'2	s   C
 
ADDc                   #    U R                   R                  [        R                  La|  U R                   R                  [        R                  L aU  [        R
                  " S[        SS9  [        U R                  SS9" U5      I S h  vN   U R                  U5      I S h  vN $ U R                  U5      I S h  vN   U R                  U5      I S h  vN $  NO N8 N! N
7f)NzSupport for subclasses of RemoteUserMiddleware that override process_request() without overriding aprocess_request() is deprecated.rK   )category
stacklevelT)thread_sensitive)	r_   r+   rW   aprocess_requestwarningswarnr   r   r[   r)   s     r   rc   RemoteUserMiddleware.__acall__   s      NN**2F2V2VV//3G3X3XXMM 2   4 4tLWUUU**7333##G,,,&&w/// V3,/sH   BC C	C !C"C :C;C CC C C C c                   #    [        US5      (       d  [        S5      e UR                  SU R                  -      nUR                  5       I S h  vN nUR                  (       a=  UR                  5       U R                  X!5      :X  a  g U R                  U5      I S h  vN   [        R                  " XS9I S h  vN nU(       a%  X1l        [        R                  " X5      I S h  vN   g g ! [         aX    U R
                  (       aD  UR                  5       I S h  vN  nUR                  (       a  U R                  U5      I S h  vN     g f = f GN N N Nr7f)Nr(   rg   HTTP_rh   )r   r   rj   rk   rl   rm   r   r8   _aremove_invalid_userro   rp   r	   aauthenticater(   aloginrs   s       r   rz   %RemoteUserMiddleware.aprocess_request   s(    w''&: 
	||Gdkk$9:H ]]_$     "d&9&9(&LL 00999 ''FF  L++g,,,	 1  	 --$]]_,,((44W===	 % : G
 -s   EC+ EEAEEE9E:*E$E%E+.ED*EEE
EEEEEEc                     UR                   [        R                     n[        R                  " U5      n UR	                  U5      nU$ ! [
         a     U$ f = f)zZ
Allow the backend to clean the username, if the backend defines a
clean_username method.
)r#   r	   BACKEND_SESSION_KEYr   rp   AttributeError)r*   rt   r   backend_strbackends        r   rp   #RemoteUserMiddleware.clean_username   s]    
 ood&>&>?##K0	--h7H   		s   A 
AAc                     [        UR                  R                  [        R                  S5      5      n[        U[        5      (       a  [        R                  " U5        gg! [         a    [        R                  " U5         gf = fz
Remove the current authenticated user in the request which is invalid
but only if the user is authenticated via the RemoteUserBackend.
 N)	r   r#   getr	   r   
isinstancer   logoutImportErrorr*   r   stored_backends      r   rn   )RemoteUserMiddleware._remove_invalid_user   si    
		%)##D$<$<bAN .*;<<G$ =	  	!KK 	!s   3A" " BBc                 R  #     [        UR                  R                  [        R                  S5      I Sh  vN 5      n[        U[        5      (       a  [        R                  " U5      I Sh  vN   gg N= N! [         a"    [        R                  " U5      I Sh  vN     gf = f7fr   )	r   r#   agetr	   r   r   r   alogoutr   r   s      r   r   *RemoteUserMiddleware._aremove_invalid_user  s     
		,)oo**4+C+CRHHN .*;<<ll7+++ = I ,  	(,,w'''	(sU   B'2A8 A4A8 .B'-A6.B'4A8 6B'8#B$BB$!B'#B$$B')r[   r\   )r.   r/   r0   r1   rU   sync_capableasync_capabler^   rk   rm   rd   r+   rc   rz   rp   rn   r   r2   __classcell__)r_   s   @r   rW   rW   ^   sP      LM F $*%&N0$(-T% , ,r   rW   c                       \ rS rSrSrSrSrg)PersistentRemoteUserMiddlewarei  ao  
Middleware for web-server provided authentication on logon pages.

Like RemoteUserMiddleware but keeps the user authenticated even if
the ``request.META`` key is not found in the request. Useful for
setups when the external authentication is only expected to happen
on some "logon" URL and the rest of the application wants to use
Django's authentication mechanism.
Fr-   N)r.   r/   r0   r1   rU   rm   r2   r-   r   r   r   r     s     !&r   r   )#r{   	functoolsr   urllib.parser   asgiref.syncr   r   r   django.confr   django.contribr	   django.contrib.authr
   r   django.contrib.auth.backendsr   django.contrib.auth.viewsr   django.core.exceptionsr   django.shortcutsr   django.utils.deprecationr   r   django.utils.functionalr   r   r   r    r4   rW   r   r-   r   r   <module>r      sl      ! R R    A : 7 7 ( N 4 !0 0/
o /
dw, w,t&%9 &r   