o
    hy                     @   s   d dl mZ d dlmZmZmZ d dlmZ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 G d	d
 d
Zdd Zedd Zdeeeef  fddZdS )    )contextmanager)AnyDictOptional)SimpleLazyObjectempty)app_settings)get_pending_stage)ImmediateHttpResponse)Client)
sessionkitc                   @   s4   e Zd Zdd Zedd Zdd Zedd Zd	S )
AuthenticationStatusc                 C   s
   || _ d S N)request)selfr    r   X/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/headless/internal/authkit.py__init__      
zAuthenticationStatus.__init__c                 C   s
   | j jjS r   )r   useris_authenticatedr   r   r   r   r      s   
z%AuthenticationStatus.is_authenticatedc                 C   s
   t | jS r   )r	   r   r   r   r   r   r	      r   z&AuthenticationStatus.get_pending_stagec                 C   s(   t jsdS ddlm} t|j| jS )NFr   )flows)allauth_settingsSOCIALACCOUNT_ENABLEDallauth.socialaccount.internalr   boolsignupget_pending_signupr   )r   r   r   r   r   has_pending_signup   s   z'AuthenticationStatus.has_pending_signupN)__name__
__module____qualname__r   propertyr   r	   r   r   r   r   r   r      s    
r   c                 C   s:   dD ]}t | |rt| | qt| jtrt| j_d S d S )N)_cached_user_acached_user)hasattrdelattr
isinstancer   r   r   _wrapped)r   attrr   r   r   purge_request_user_cache"   s   

r+   c              	   c   s    ddl m} | j}| j}zTt | _t|  tj}|	| }|r7|
|}|s0t|| dd|| _t|  | j| jj_| jjjj d V  W | jjrU| j sU| j  || _|| _d| jd< d S | jjrp| j sp| j  || _|| _d| jd< w )Nr   )UnauthorizedResponsei  )statusFCSRF_COOKIE_NEEDS_UPDATE)allauth.headless.base.responser,   r   sessionr   new_sessionr+   r   TOKEN_STRATEGYget_session_tokenlookup_sessionr
   allauthheadless	_pre_userpkmodifiedis_emptysaveMETA)r   r,   old_userold_sessionstrategysession_tokenr0   r   r   r   authentication_context*   s8   




rA   returnc                 C   sR   | j jjtjkr
dS | jjsdS | j jj}|jr!|j| jjkr!dS t	j
}|| S )z?
    Determines if a new access token needs to be exposed.
    N)r5   r6   clientr   APPr   r   r7   r8   r   r2   create_access_token_payload)r   pre_userr?   r   r   r   expose_access_tokenI   s   

rG   N)
contextlibr   typingr   r   r   django.utils.functionalr   r   r5   r   r   !allauth.account.internal.stagekitr	   allauth.core.exceptionsr
   allauth.headlessallauth.headless.constantsr   allauth.headless.internalr   r   r+   rA   strrG   r   r   r   r   <module>   s    
