o
    h>!                     @   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mZmZmZmZmZmZ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" G dd dee"j#Z$G dd de"j#Z%G dd de"j#Z&G dd dee"j#Z'G dd de"j#Z(G dd de(Z)G dd de"j#Z*G dd dee"j#Z+G dd de"j#Z,G dd de,Z-G d d! d!e,Z.G d"d# d#ee"j#Z/G d$d% d%ee"j#Z0G d&d' d'ee"j#Z1G d(d) d)ee"j#Z2G d*d+ d+ee"j#Z3d,S )-    )ValidationError)validate_email)app_settings)get_adapter)
PhoneField)	AddEmailFormBaseSignupFormChangePhoneFormConfirmLoginCodeFormReauthenticateFormRequestLoginCodeFormResetPasswordFormUserTokenFormVerifyPhoneForm)flows)compare_code)EmailAddressLoginget_emailconfirmation_model)context)inputsc                       ,   e Zd Ze Z fddZdd Z  ZS )SignupInputc                    sB   t  j|i | tjd}|s| jd= d S |d | jd _d S )N	password1passwordrequired)super__init__account_settingsSIGNUP_FIELDSgetfieldsr   )selfargskwargsr   	__class__ Z/var/www/html/env_mimamsha/lib/python3.10/site-packages/allauth/headless/account/inputs.pyr   !   s
   zSignupInput.__init__c                 C   s   | j d }t |S )Nr   )cleaned_dataget_account_adapterclean_password)r"   r   r'   r'   r(   r+   )   s   
zSignupInput.clean_password)	__name__
__module____qualname__r   	CharFieldr   r   r+   __classcell__r'   r'   r%   r(   r      s    r   c                       sR   e Zd ZejddZejddZeddZ	e Z
 fddZ fddZ  ZS )
LoginInputFr   c                    sZ   t  j|i | dD ]}|tjvr| j|= qttjdkr+d| jtttj _d S d S )N)usernameemailphone   T)	r   r   r   LOGIN_METHODSr!   lennextiterr   )r"   r#   r$   fieldr%   r'   r(   r   5   s   
zLoginInput.__init__c           	         s   t   }| jr
|S i }tjD ]}||}|d ur%|| j v r%|||< qt|dkr2t	 
d|d}|r|tt| }||d< t	 jtjfi |}|rmt||dd| _tjtj| jrkt	 
d|S d|j }| dt	 
| |S )Nr6   invalid_loginr   r4   userr4   too_many_login_attemptsz%s_password_mismatch)r   cleanerrorsr   r7   r    datakeysr8   r*   validation_errorr9   r:   authenticater   requestr   loginr   is_login_rate_limitedvalue	add_error)	r"   r)   credentialslogin_methodrI   r   auth_methodr>   
error_coder%   r'   r(   r@   =   s8   




zLoginInput.clean)r,   r-   r.   r   r/   r3   
EmailFieldr4   r   r5   r   r   r@   r0   r'   r'   r%   r(   r1   .   s    
r1   c                       r   )VerifyEmailInputc                    s$   | dd | _t j|i | d S )Nprocess)poprQ   r   r   r"   r#   r$   r%   r'   r(   r   ^   s   zVerifyEmailInput.__init__c                 C   s   | j d }| jrt|| jjdst dd}| jj}n#t }||}|o+|	  }|s:t t
jr7dd|j}|| _|rL| sLt d|S )Nkeyactualexpectedincorrect_codeTinvalid_or_expired_keyemail_taken)r)   rQ   r   coder*   rD   email_addressr   from_keykey_expiredr   "EMAIL_VERIFICATION_BY_CODE_ENABLEDverificationcan_set_verified)r"   rT   validr\   modelr`   r'   r'   r(   	clean_keyb   s*   


zVerifyEmailInput.clean_key)	r,   r-   r.   r   r/   rT   r   rd   r0   r'   r'   r%   r(   rP   [       rP   c                   @      e Zd ZdS )RequestPasswordResetInputNr,   r-   r.   r'   r'   r'   r(   rg   z       rg   c                       s<   e Zd Ze Z fddZdd Zdd Zdd Z	  Z
S )	ResetPasswordKeyInputc                    s2   | dd | _| dd | _t j|i | d S )Nr>   r[   )rR   r>   r[   r   r   rS   r%   r'   r(   r      s   zResetPasswordKeyInput.__init__c                 C   s   t jr|  S |  S )N)r   PASSWORD_RESET_BY_CODE_ENABLED_clean_key_code_clean_key_link)r"   r'   r'   r(   rd      s   zResetPasswordKeyInput.clean_keyc                 C   s(   | j d }t|| jdst d|S )NrT   rU   rX   )r)   r   r[   r*   rD   )r"   rT   r'   r'   r(   rl      s   
z%ResetPasswordKeyInput._clean_key_codec                 C   sJ   | j d }|d\}}}t||dd}| st d|j| _|S )NrT   -)uidb36rT   )rB   invalid_password_reset)r)   	partitionr   is_validr*   rD   
reset_userr>   )r"   rT   ro   _subkey
token_formr'   r'   r(   rm      s   
z%ResetPasswordKeyInput._clean_key_link)r,   r-   r.   r   r/   rT   r   rd   rl   rm   r0   r'   r'   r%   r(   rj   ~   s    rj   c                       s$   e Zd Ze Z fddZ  ZS )ResetPasswordInputc              
      st   t   }| jd}| jr8|d ur8zt j|| jd W |S  ty7 } z| d| W Y d }~|S d }~ww |S )Nr   r>   )	r   r@   r)   r    r>   r*   r+   r   rJ   )r"   r)   r   er%   r'   r(   r@      s   
zResetPasswordInput.clean)r,   r-   r.   r   r/   r   r@   r0   r'   r'   r%   r(   rw      s    rw   c                       s@   e Zd ZejddZe Z fddZdd Zdd Z	  Z
S )	ChangePasswordInputFr2   c                    s4   | d| _t j|i | | j | jd _d S )Nr>   current_password)rR   r>   r   r   has_usable_passwordr!   r   rS   r%   r'   r(   r      s   zChangePasswordInput.__init__c                 C   s*   | j d }|r| j|st d|S )Nr{   enter_current_password)r)   r>   check_passwordr*   rD   )r"   r{   r'   r'   r(   clean_current_password   s
   
z*ChangePasswordInput.clean_current_passwordc                 C   s    | j d }t }|j|| jdS )Nnew_passwordrx   )r)   r*   r+   r>   )r"   r   adapterr'   r'   r(   clean_new_password   s   
z&ChangePasswordInput.clean_new_password)r,   r-   r.   r   r/   r{   r   r   r   r   r0   r'   r'   r%   r(   rz      s    rz   c                   @   rf   )AddEmailInputNrh   r'   r'   r'   r(   r      ri   r   c                       r   )SelectEmailInputc                    s"   | d| _t j|i | d S )Nr>   )rR   r>   r   r   rS   r%   r'   r(   r      s   zSelectEmailInput.__init__c                 C   sD   | j d }t| z
tjj| j|dW S  tjy!   t dw )Nr4   r=   unknown_email)	r)   r   r   objectsget_for_userr>   DoesNotExistr   rD   r"   r4   r'   r'   r(   clean_email   s   
zSelectEmailInput.clean_email)	r,   r-   r.   r   r/   r4   r   r   r0   r'   r'   r%   r(   r      re   r   c                       s   e Zd Z fddZ  ZS )DeleteEmailInputc                    &   t   }tj|st d|S )Ncannot_remove_primary_email)r   r   r   manage_emailcan_delete_emailr*   rD   r   r%   r'   r(   r         
zDeleteEmailInput.clean_email)r,   r-   r.   r   r0   r'   r'   r%   r(   r      s    r   c                       s(   e Zd ZejddZ fddZ  ZS )MarkAsPrimaryEmailInputTr2   c                    r   )Nunverified_primary_email)r   r   r   r   can_mark_as_primaryr*   rD   r   r%   r'   r(   r      r   z#MarkAsPrimaryEmailInput.clean_email)r,   r-   r.   r   BooleanFieldprimaryr   r0   r'   r'   r%   r(   r      s    r   c                   @   rf   )ReauthenticateInputNrh   r'   r'   r'   r(   r      ri   r   c                   @   rf   )RequestLoginCodeInputNrh   r'   r'   r'   r(   r      ri   r   c                   @   rf   )ConfirmLoginCodeInputNrh   r'   r'   r'   r(   r      ri   r   c                   @   rf   )VerifyPhoneInputNrh   r'   r'   r'   r(   r      ri   r   c                   @   rf   )ChangePhoneInputNrh   r'   r'   r'   r(   r      ri   r   N)4django.core.exceptionsr   django.core.validatorsr   allauth.accountr   r   allauth.account.adapterr   r*   allauth.account.fieldsr   allauth.account.formsr   r   r	   r
   r   r   r   r   r   allauth.account.internalr    allauth.account.internal.textkitr   allauth.account.modelsr   r   r   allauth.corer   allauth.headless.adapter!allauth.headless.internal.restkitr   Inputr   r1   rP   rg   rj   rw   rz   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   <module>   s8    ,-
