o
    &zhb                     @   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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 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )    )ValidationError)app_settings)get_adapter)assess_unique_email)complete_signupprevent_enumeration)user_username)SignupClosedException)headed_redirect_response)SocialLoginc                 C   s   | j d}|rt|S d S Nsocialaccount_sociallogin)sessiongetr   deserialize)requestdata r   f/var/www/html/kangema/venv/lib/python3.10/site-packages/allauth/socialaccount/internal/flows/signup.pyget_pending_signup   s   
r   c                 C   s   |  | jd< tdS )Nr   socialaccount_signup)	serializer   r
   r   socialloginr   r   r   redirect_to_signup   s   r   c                 C   s   | j dd  d S r   )r   pop)r   r   r   r   clear_pending_signup   s   r   c                 C   s(   t |  || \}}|st| |}|S )N)r   try_savecomplete_social_signup)r   r   formuserrespr   r   r   signup_by_form   s
   
r"   c                 C   sF   t  | |}|sdS t| |\}}|sd|fS t| |\}}||fS )NFNF)r   is_auto_signup_allowedprocess_auto_signup_emailprocess_auto_signup_phone)r   r   auto_signupr!   r   r   r   process_auto_signup&   s   r(   c                 C   s   d }|j r|j d j}|r5t|}|du rd}|d fS |du r%d}|d fS |d u s+J t| |d}d|fS tjr>d}|d fS d}|d fS )Nr   TF)email)email_addressesr)   r   r   r   EMAIL_REQUIRED)r   r   r)   
assessmentr'   r!   r   r   r   r%   1   s&   r%   c                 C   s@   t jd}|r|d sdS |jsdS t |j}|rdS dS )Nphonerequired)TNr#   )account_settingsSIGNUP_FIELDSr   r-   get_account_adapterget_user_by_phone)r   r   phone_fieldexisting_userr   r   r   r&   X   s   r&   c                 C   s   t  | |s
t t| |\}}|r|S |st| |}|S tjr?t|j}z	t	| 
| W n ty>   t|jd Y nw t  j| |d d t| |}|S )N )r   )r   is_open_for_signupr	   r(   r   r/   USER_MODEL_USERNAME_FIELDr   r    r1   clean_usernamer   	save_userr   )r   r   r'   r!   usernamer   r   r   process_signupg   s$   


r;   c                 C   s    t | |jtj|| d|idS )Nr   )r    email_verificationredirect_urlsignal_kwargs)r   r    r   EMAIL_VERIFICATIONget_redirect_urlr   r   r   r   r      s   r   N) django.formsr   allauth.accountr   r/   allauth.account.adapterr   r1   +allauth.account.internal.flows.manage_emailr   %allauth.account.internal.flows.signupr   r   allauth.account.utilsr   allauth.core.exceptionsr	   allauth.core.internal.httpkitr
   allauth.socialaccountallauth.socialaccount.adapterallauth.socialaccount.modelsr   r   r   r   r"   r(   r%   r&   r;   r   r   r   r   r   <module>   s(    '