o
    hk                     @   s(  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 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eZG dd deZG dd deZG dd deZG dd deZG dd deZ dd Z!G dd deZ"G dd deZ#dS )    )
HTTPStatus)app_settingsget_adapter)LoginMethod)get_authentication_records)flows)LOGIN_SESSION_KEY)Flow)authkit)APIResponsec                       s@   e Zd Zd fdd	Zdd Zdd Zded	dfd
dZ  ZS )BaseAuthenticationResponseNc                    s   i }|r|j rt }|||d< t||d< |ptj}n|p!tj}|tjkr/| |||d< d|o4|j i}t j	||||d d S )Nusermethodsr   is_authenticated)datametastatus)
r   r   serialize_userr   r   OKUNAUTHORIZED
_get_flowssuper__init__)selfrequestr   r   r   adapterr   	__class__ U/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/headless/base/response.pyr      s"   




z#BaseAuthenticationResponse.__init__c                 C   sV  t |}g }|r|jr|tj| nEtjs!|	dt
ji tjr,|	dt
ji t |r=tjs=|	dt
ji tjrMddlm} ||| tjr[tjr[|	dt
ji d }| }|rg|j}n|jt}t|trt|}|r|dd}	|r|t
j kr| !||	 | "||	 tjstj#rddl$m%}
 |	t
j&t'|
j()|d |S )Nidr   )provider_flowsT)r!   
is_pending)password_reset_by_code)*r   AuthenticationStatusr   extendr   reauthenticationget_reauthentication_flowsallauth_settingsSOCIALACCOUNT_ONLYappendr
   LOGINaccount_settingsLOGIN_BY_CODE_ENABLEDLOGIN_BY_CODEget_account_adapteris_open_for_signupSIGNUPSOCIALACCOUNT_ENABLED'allauth.headless.socialaccount.responser"   MFA_ENABLEDmfa_settingsPASSKEY_LOGIN_ENABLEDMFA_LOGIN_WEBAUTHNget_pending_stagekeysessiongetr	   
isinstancestrMFA_AUTHENTICATE_enrich_mfa_flow_upsert_pending_flowPASSWORD_RESET_BY_CODE_ENABLEDallauth.account.internal.flowsr$   PASSWORD_RESET_BY_CODEbool PasswordResetVerificationProcessresume)r   r   r   auth_statusretr"   	stage_keystagelskpending_flowr$   r   r   r    r   '   s\   





z%BaseAuthenticationResponse._get_flowsc                    s8   t  fdd|D d }|r|  d S |  d S )Nc                 3   s$    | ]}|d   d  kr|V  qdS )r!   Nr   ).0flowrM   r   r    	<genexpr>^   s   " zBBaseAuthenticationResponse._upsert_pending_flow.<locals>.<genexpr>)nextupdater+   )r   r   rM   rO   r   rP   r    rA   ]   s   z/BaseAuthenticationResponse._upsert_pending_flowrO   returnc                 C   sX   ddl m} ddlm} | }g }|jD ]}|j|jj|gdr%|| q||d< d S )Nr   r   )Authenticator)typesrV   )	allauth.mfa.adapterr   allauth.mfa.modelsrU   Typeis_mfa_enabledloginr   r+   )r   rK   rO   get_mfa_adapterrU   r   rV   typr   r   r    r@   d   s   

z+BaseAuthenticationResponse._enrich_mfa_flow)NN)	__name__
__module____qualname__r   r   rA   dictr@   __classcell__r   r   r   r    r      s
    6r   c                       s(   e Zd Z fddZedd Z  ZS )AuthenticationResponsec                    s   t  j||jd d S )N)r   )r   r   r   r   r   r   r   r    r   q      zAuthenticationResponse.__init__c                 C   s   t |tr|S t|S )a5  
        The response might be a headed redirect to e.g. the confirmation
        email page, because allauth.account is not (much) headless
        aware. Also, what if an adapter method return headed responses in
        post_login()?  So, let's ensure we always return a headless
        response.
        )r=   rc   )clsr   responser   r   r    from_responset   s   
	z$AuthenticationResponse.from_response)r^   r_   r`   r   classmethodrh   rb   r   r   r   r    rc   p   s    rc   c                          e Zd Z fddZ  ZS )ReauthenticationResponsec                    s   t  j||jtjd d S N)r   r   )r   r   r   r   r   rd   r   r   r    r      s   z!ReauthenticationResponse.__init__r^   r_   r`   r   rb   r   r   r   r    rk          rk   c                       s"   e Zd Zejf fdd	Z  ZS )UnauthorizedResponsec                    s   t  j|d |d d S rl   )r   r   )r   r   r   r   r   r    r      re   zUnauthorizedResponse.__init__)r^   r_   r`   r   r   r   rb   r   r   r   r    ro      s    ro   c                       rj   )ForbiddenResponsec                       t  j|tjd d S N)r   )r   r   r   	FORBIDDENrd   r   r   r    r      re   zForbiddenResponse.__init__rm   r   r   r   r    rp      rn   rp   c                       rj   )ConflictResponsec                    rq   rr   )r   r   r   CONFLICTrd   r   r   r    r      re   zConflictResponse.__init__rm   r   r   r   r    rt      rn   rt   c                 C   s   t j}t|t | t jt jt jd}tj	|v r&tj
|v r&d|d< d|iS tj	|v r3d|d< d|iS tj
|v r<d|d< d|iS )N)login_methodsr1   "email_verification_by_code_enabledlogin_by_code_enabledpassword_reset_by_code_enabledusername_emailauthentication_methodemailusernameaccount)r-   LOGIN_METHODSlistr0   r1   "EMAIL_VERIFICATION_BY_CODE_ENABLEDr.   rB   r   EMAILUSERNAME)r   rv   r   r   r   r    get_config_data   s    


r   c                       rj   )ConfigResponsec                    sx   t |}tjrddlm } ||| tjr$ddlm } ||| tjr4ddlm } ||| t	 j
||dS )Nr   )r   )r   )r   r)   r3   r4   rS   r5   allauth.headless.mfa.responseUSERSESSIONS_ENABLED&allauth.headless.usersessions.responser   r   )r   r   r   get_socialaccount_config_dataget_mfa_config_dataget_usersessions_config_datar   r   r    r      s   zConfigResponse.__init__rm   r   r   r   r    r      rn   r   c                       rj   )RateLimitResponsec                    rq   rr   )r   r   r   TOO_MANY_REQUESTSrd   r   r   r    r      re   zRateLimitResponse.__init__rm   r   r   r   r    r      rn   r   N)$httpr   allauthr   r)   allauth.accountr-   allauth.account.adapterr   r0   allauth.account.app_settingsr   allauth.account.authenticationr   allauth.account.internalr   !allauth.account.internal.stagekitr	   allauth.headless.adapterallauth.headless.constantsr
   allauth.headless.internalr   *allauth.headless.internal.restkit.responser   allauth.mfar6   r   rc   rk   ro   rp   rt   r   r   r   r   r   r   r    <module>   s,    _