U
    ÔÉ>iN  ã                   @   s¬   d dl mZmZ d dl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 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S )é    )ÚOptionalÚType)Úclassonlymethod)Ú
LoginStageÚLoginStageController)ÚReauthenticationRequired)Úresponse)ÚClient)Ú
decorators)ÚRESTViewc                       s,   e Zd ZdZedd„ ƒZ‡ fdd„Z‡  ZS )ÚAPIViewNc                 K   s4   | j f |Ž}|d tjkr&t |¡}n
t |¡}|S )NÚclient)Zas_viewr	   ZAPPr
   Zapp_viewZbrowser_view)ÚclsZ
initkwargsZ	view_func© r   ú?/tmp/pip-unpacked-wheel-upujnpc2/allauth/headless/base/views.pyÚas_api_view   s
    
zAPIView.as_api_viewc                    s<   zt ƒ j|f|ž|ŽW S  tk
r6   t | j¡ Y S X d S ©N)ÚsuperÚdispatchr   r   ZReauthenticationResponseÚrequest©Úselfr   ÚargsÚkwargs©Ú	__class__r   r   r      s    zAPIView.dispatch)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   Ú__classcell__r   r   r   r   r      s   
r   c                       sB   e Zd ZU dZeee  ed< ‡ fdd„Zdd„ Z	dd„ Z
‡  ZS )	ÚAuthenticationStageAPIViewNÚstage_classc                    s6   t  || jj¡| _| js"t |¡S tƒ j|f|ž|ŽS r   )	r   Zenterr!   ÚkeyÚstager   ÚUnauthorizedResponser   Úhandler   r   r   r   r%   #   s    
z!AuthenticationStageAPIView.handlec                 C   s   t  | j¡S r   )r   r$   r   ©r   r   r   r   Úrespond_stage_error)   s    z.AuthenticationStageAPIView.respond_stage_errorc                 C   s   | j  ¡  t | j¡S r   )r#   Úexitr   ÚAuthenticationResponser   r&   r   r   r   Úrespond_next_stage,   s    
z-AuthenticationStageAPIView.respond_next_stage)r   r   r   r!   r   r   r   Ú__annotations__r%   r'   r*   r   r   r   r   r   r        s   
r    c                       s   e Zd Z‡ fdd„Z‡  ZS )ÚAuthenticatedAPIViewc                    s&   |j jst |¡S tƒ j|f|ž|ŽS r   )ÚuserÚis_authenticatedr   r)   r   r   r   r   r   r   r   2   s    
zAuthenticatedAPIView.dispatch)r   r   r   r   r   r   r   r   r   r,   1   s   r,   c                   @   s   e Zd Zdd„ ZdS )Ú
ConfigViewc                 O   s
   t  |¡S )z—
        The frontend queries (GET) this endpoint, expecting to receive
        either a 401 if no user is authenticated, or user information.
        )r   ZConfigResponser   r   r   r   Úget9   s    zConfigView.getN)r   r   r   r0   r   r   r   r   r/   8   s   r/   N)Útypingr   r   Zdjango.utils.decoratorsr   Zallauth.account.stagesr   r   Zallauth.core.exceptionsr   Zallauth.headless.baser   Zallauth.headless.constantsr	   Zallauth.headless.internalr
   Z'allauth.headless.internal.restkit.viewsr   r   r    r,   r/   r   r   r   r   Ú<module>   s   