a
    Qx_                     @   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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mZ dd Zdd Zej ddfddZ!dd Z"dd Z#dd Z$dd Z%dd Z&dd  Z'dS )!    )messages)ValidationError)HttpResponseRedirect)render)reverse)app_settings)get_adapter)complete_signupperform_loginuser_username)ImmediateHttpResponse   )r   signals)SocialLogin)	AuthErrorAuthProcessc                 C   s   t | | |}|s4| | jd< td}t|}ntjrvt|j	}zt
| | W n tyt   t|j	d Y n0 t | | |st| dtj S t | j| |d d t| |}|S )NZsocialaccount_socialloginZsocialaccount_signup zaccount/signup_closed.)Zform)r   Zis_auto_signup_allowed	serializeZsessionr   r   account_settingsZUSER_MODEL_USERNAME_FIELDr   userget_account_adapterZclean_usernamer   Zis_open_for_signupr   TEMPLATE_EXTENSIONZ	save_usercomplete_social_signup)requestsocialloginZauto_signupurlretusername r   U/var/www/html/Ranjet/env/lib/python3.9/site-packages/allauth/socialaccount/helpers.py_process_signup   s&    


r    c                 C   s    t | |jtj|| d|idS )Nr   )Zemail_verificationZredirect_urlsignal_kwargs)r
   r   r   EMAIL_VERIFICATIONget_redirect_urlr   r   r   r   r   _login_social_account/   s    r%   Nc              
   C   s   z(|d u ri }t | j| ||||d W n* tyR } z|jW  Y d }~S d }~0 0 |tjkrjttdS d|||di}|| t	| dt
j |S )N)error	exceptionextra_contextZsocialaccount_login_cancelledZ
auth_error)Zprovidercoder'   z#socialaccount/authentication_error.)r   Zauthentication_errorr   responser   Z	CANCELLEDr   r   updater   r   r   )r   Zprovider_idr&   r'   r(   econtextr   r   r   render_authentication_error9   s4    


r.   c                 C   s   | j jrttdS tj}d}d }|jr\|j | j kr@tj}d}qd}d}tj	j
t| |d n$d}|| | j  tjj
t| |d t| | |j}|| p|}t| j| ||||dd	 t|S )
NZsocialaccount_connectionsz,socialaccount/messages/account_connected.txtz2socialaccount/messages/account_connected_other.txtupdatedz4socialaccount/messages/account_connected_updated.txtZsenderr   r   Zadded)r   action)Zmessage_context)r   Zis_anonymousr   r   r   INFOis_existingERRORr   social_account_updatedsendr   connectZsocial_account_addedr   Zget_connect_redirect_urlZaccountr#   r   Zadd_message)r   r   levelmessager1   Zdefault_nextnext_urlr   r   r   _add_social_account]   s<    r;   c              
   C   s   |j r
J |  zjt| | | tjjt| |d |jd}|t	j
krXt| |W S |t	jkrnt| |W S t| |W S W n* ty } z|jW  Y d }~S d }~0 0 d S )Nr0   process)r3   lookupr   Zpre_social_loginr   r6   r   stategetr   ZREDIRECT_social_login_redirectZCONNECTr;   _complete_social_loginr   r*   )r   r   r<   r,   r   r   r   complete_social_login   s    


rB   c                 C   s   | | pd}t|S )N/)r#   r   )r   r   r:   r   r   r   r@      s    r@   c                 C   sH   | j jrt| |  |jr:t| |}tjjt	| |d n
t
| |}|S )Nr0   )r   Zis_authenticatedr   Zlogoutr3   r%   r   r5   r6   r   r    )r   r   r   r   r   r   rA      s    

rA   c                 C   s    t | |jtj|| d|idS )Nr   )r!   )r	   r   r   r"   r#   r$   r   r   r   r      s    r   c                 C   s(   |  d\}}}t||gd}t||S )N.)fromlist)
rpartition
__import__getattr)pathmodname_attrmr   r   r   import_path   s    rN   )(Zdjango.contribr   Zdjango.formsr   Zdjango.httpr   Zdjango.shortcutsr   Zdjango.urlsr   Zallauth.accountr   r   Zallauth.account.adapterr   r   Zallauth.account.utilsr	   r
   r   Zallauth.exceptionsr   r   r   ZadapterZmodelsr   Zproviders.baser   r   r    r%   UNKNOWNr.   r;   rB   r@   rA   r   rN   r   r   r   r   <module>   s0   
$,