U
    >i                     @   s   d dl mZmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ dd	d
ddZdd Zdd Zd	S )    )PermissionDeniedValidationError)HttpResponseRedirect)app_settings)ImmediateHttpResponseReauthenticationRequiredSignupClosedException)httpkit)AuthenticationStatus)flowsstatekit)	AuthErrorAuthProcessN)returnc           
      C   s   d}|r4| d}|dkr4| d}|r4t| |}d|i}|dk	rf| d}| d}	|d |d< ntj}d}	tj|d< |sdS |	st| d	pd
}	t	|	|}	t
t|	dS )zW
    Called at a time when it is not clear whether or not this is a headless flow.
    Nstatestate_iderrorheadlessnextprocesserror_processZsocialaccount_login_error/)getr   Zunstash_stateallauth_settingsZHEADLESS_ONLYr   ZLOGINr	   Zget_frontend_urladd_query_paramsr   r   )
requestZproviderr   	exceptionZextra_contextr   r   paramsr   next_url r   K/tmp/pip-unpacked-wheel-upujnpc2/allauth/headless/socialaccount/internal.pyon_authentication_error   s*    




r!   c                 C   s   t jj| |ddS )NTZraises)r   logincomplete_login)r   socialloginr   r   r    complete_token_login3   s    r&   c              
   C   s   d}zt jj| |dd W nj tk
r2   d}Y n~ tk
rH   d}Y nh tk
r^   d}Y nR tk
r } z
|j}W 5 d}~X Y n,X t| }t	|j
 |j |  grtj}|jd }|rt|||jd d	}t|S )
z0
    Called when `sociallogin.is_headless`.
    NTr"   Zreauthentication_requiredZsignup_closedZpermission_deniedr   r   )r   r   )r   r#   r$   r   r   r   r   coder
   allis_authenticatedZhas_pending_signupZget_pending_stager   UNKNOWNr   r	   r   r   )r   r%   r   estatusr   r   r   r    r$   7   s4    

r$   )NNNN)Zdjango.core.exceptionsr   r   Zdjango.httpr   Zallauthr   r   Zallauth.core.exceptionsr   r   r   Zallauth.core.internalr	   Z!allauth.headless.internal.authkitr
   Zallauth.socialaccount.internalr   r   Z.allauth.socialaccount.providers.base.constantsr   r   r!   r&   r$   r   r   r   r    <module>   s        #