
    Sњh                         S SK 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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 5       rS\4S jr\S 5       rS\4S jrS\4S jrg)    N)SimpleNamespace)HttpResponseRedirect)NoReverseMatchreverse)sync_and_async_middleware)iscoroutinefunctionsync_to_async)get_adapter)flows)context)ImmediateHttpResponseReauthenticationRequiredc                 T   ^  [        T 5      (       a  U 4S jnOU 4S jnS nX!l        U$ )Nc                    >#    [        5       U l        [        R                  " U 5         T" U 5      I S h  vN n[	        X5      (       a  [        U 5      I S h  vN nUsS S S 5        $  N2 N! , (       d  f       g = f7fN)r   allauthr   request_context_should_redirect_accounts_aredirect_accountsrequestresponseget_responses     UD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\allauth/account/middleware.py
middleware%AccountMiddleware.<locals>.middleware   s\     -/GO((1!-g!66,W??%8%AAH	 216A 21s>   &A=A,A("A,A*A,
A=(A,*A,,
A:6A=c                    > [        5       U l        [        R                  " U 5         T" U 5      n[	        X5      (       a  [        U 5      nUsS S S 5        $ ! , (       d  f       g = fr   )r   r   r   r   r   _redirect_accountsr   s     r   r   r      sI    -/GO((1'0,W??1':H	 211s   %A
A$c                 (   [        U[        5      (       a  UR                  $ [        U[        5      (       a\  [	        S5      n[        5       R                  U R                  5      nU(       a  US   S   n[        R                  R                  X5      $ g )Naccount_loginr   url)
isinstancer   r   r   r   r
   get_reauthentication_methodsuserr   reauthenticationsuspend_request)r   	exceptionredirect_urlmethodss       r   process_exception,AccountMiddleware.<locals>.process_exception&   sw    i!677%%%	#;<<"?3L!m@@NG&qz%0))99'PP =    )r   r*   )r   r   r*   s   `  r   AccountMiddlewarer-      s,    <((	 	 Q $5 r,   returnc                     UR                   S:w  a  g [        S5      n[        S5      n[        R                  R                  X#/5      n[        U5      S::  d  X@R                  :w  a  gg! [         a     gf = f)ai  
URLs should be hackable. Yet, assuming allauth is included like this...

    path("accounts/", include("allauth.urls")),

... and a user would attempt to navigate to /accounts/, a 404 would be
presented. This code catches that 404, and redirects to either the email
management overview or the login page, depending on whether or not the user
is authenticated.
i  Fr    account_email   T)status_coder   r   ospathcommonprefixlen)r   r   
login_path
email_pathprefixs        r   r   r   4   sx     s"_-
_-
 WW!!:":;F
6{a6\\1   s   A) )
A65A6c                     U R                   $ r   )r$   )r   s    r   _async_get_userr;   O   s    <<r,   c                    #    [        S5      n[        S5      n[        U S5      (       a  U R                  5       I S h  vN nO[        U 5      I S h  vN n[	        UR
                  (       a  U5      $ U5      $  N: N(7f)Nr0   r    auser)r   hasattrr=   r;   r   is_authenticatedr   r8   r7   r$   s       r   r   r   T   sh     )J)Jw  ]]_$ %W--d.C.C
TTTT	 % .s!   ;A<A8A<A:'A<:A<c                     [        S5      n[        S5      nU R                  n[        UR                  (       a  U5      $ U5      $ )Nr0   r    )r   r$   r   r?   r@   s       r   r   r   _   s:    )J)J<<Dd.C.C
TTTTr,   )r3   typesr   django.httpr   django.urlsr   r   django.utils.decoratorsr   asgiref.syncr   r	   allauth.account.adapterr
   allauth.account.internalr   allauth.corer   allauth.core.exceptionsr   r   r-   boolr   r;   r   r    r,   r   <module>rM      sv    	 ! , / = ; / *   S    FD 6  U*> UU#7 Ur,   