o
    "4g                     @   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mZmZmZmZ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Z*G d$d% d%eejZ+d&S )'    )ImproperlyConfigured)validate_email)app_settings)get_adapter)AddEmailFormBaseSignupFormConfirmLoginCodeFormReauthenticateFormRequestLoginCodeFormResetPasswordFormUserTokenForm)flows)EmailAddressLoginget_emailconfirmation_model)context)inputsc                   @      e Zd Ze Zdd ZdS )SignupInputc                 C   s   | j d }t |S )Npassword)cleaned_dataget_account_adapterclean_password)selfr    r   h/var/www/html/authentication-server/venv/lib/python3.10/site-packages/allauth/headless/account/inputs.pyr      s   
zSignupInput.clean_passwordN)__name__
__module____qualname__r   	CharFieldr   r   r   r   r   r   r          r   c                       s<   e Zd ZejddZejddZe Z fddZ	  Z
S )
LoginInputFrequiredc           
         sr  t   }d }d }tjtjjkr|d}d}n2tjtjjkr'|d}d}n#tjtjjkrE|d}|d}d}|rD|rDt	 
dnttj|s^|s^| j|s^| |t	 
d |d}|r|si|rd|i}|rx||d< tjj}n||d< tjj}t jtjfi |}|rt||dd| _tjtj| jrt 
d|S d|j }	| dt 
|	 |S )	Nusernameemailemail_or_usernamer#   r   userr%   too_many_login_attemptsz%s_password_mismatch)supercleanaccount_app_settingsAUTHENTICATION_METHODAuthenticationMethodUSERNAMEgetEMAILUSERNAME_EMAILr   validation_errorr   errors	add_errorr   authenticater   requestr   loginr   is_login_rate_limitedvalue)
r   r   r$   r%   missing_fieldr   credentialsauth_methodr(   
error_code	__class__r   r   r+   '   sb   








zLoginInput.clean)r   r   r   r   r   r$   
EmailFieldr%   r   r+   __classcell__r   r   r?   r   r!   "   s
    r!   c                   @   r   )VerifyEmailInputc                 C   sb   | j d }t }||}|o|  }|s"t tjrdd|r/|j	 s/t d|S )Nkeyincorrect_codeinvalid_or_expired_keyemail_taken)
r   r   from_keykey_expiredr   r3   r,   "EMAIL_VERIFICATION_BY_CODE_ENABLEDemail_addresscan_set_verified)r   rD   modelconfirmationvalidr   r   r   	clean_keye   s   

zVerifyEmailInput.clean_keyN)r   r   r   r   r   rD   rP   r   r   r   r   rC   b   r    rC   c                   @      e Zd ZdS )RequestPasswordResetInputNr   r   r   r   r   r   r   rR   u       rR   c                       ,   e Zd Ze Z fddZdd Z  ZS )ResetPasswordKeyInputc                    s   d | _ t j|i | d S )N)r(   r*   __init__r   argskwargsr?   r   r   rW   |   s   zResetPasswordKeyInput.__init__c                 C   sJ   | j d }|d\}}}t||dd}| st d|j| _|S )NrD   -)uidb36rD   )datainvalid_password_reset)r   	partitionr   is_validr   r3   
reset_userr(   )r   rD   r\   _subkey
token_formr   r   r   rP      s   
zResetPasswordKeyInput.clean_key)	r   r   r   r   r   rD   rW   rP   rB   r   r   r?   r   rV   y       rV   c                       s$   e Zd Ze Z fddZ  ZS )ResetPasswordInputc                    s:   t   }| jd}| jr|d urt j|| jd |S )Nr   r(   )r*   r+   r   r0   r(   r   r   )r   r   r   r?   r   r   r+      s
   
zResetPasswordInput.clean)r   r   r   r   r   r   r+   rB   r   r   r?   r   rf      s    rf   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 )	ChangePasswordInputFr"   c                    s4   | d| _t j|i | | j | jd _d S )Nr(   current_password)popr(   r*   rW   has_usable_passwordfieldsr#   rX   r?   r   r   rW      s   zChangePasswordInput.__init__c                 C   s*   | j d }|r| j|st d|S )Nri   enter_current_password)r   r(   check_passwordr   r3   )r   ri   r   r   r   clean_current_password   s
   
z*ChangePasswordInput.clean_current_passwordc                 C   s    | j d }t }|j|| jdS )Nnew_passwordrg   )r   r   r   r(   )r   rp   adapterr   r   r   clean_new_password   s   
z&ChangePasswordInput.clean_new_password)r   r   r   r   r   ri   rp   rW   ro   rr   rB   r   r   r?   r   rh      s    rh   c                   @   rQ   )AddEmailInputNrS   r   r   r   r   rs      rT   rs   c                       rU   )SelectEmailInputc                    s"   | d| _t j|i | d S )Nr(   )rj   r(   r*   rW   rX   r?   r   r   rW      s   zSelectEmailInput.__init__c                 C   sD   | j d }t| z
tjj| j|dW S  tjy!   t dw )Nr%   r'   unknown_email)	r   r   r   objectsget_for_userr(   DoesNotExistr   r3   r   r%   r   r   r   clean_email   s   
zSelectEmailInput.clean_email)	r   r   r   r   r   r%   rW   rz   rB   r   r   r?   r   rt      re   rt   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*   rz   r   manage_emailcan_delete_emailr   r3   ry   r?   r   r   rz         
zDeleteEmailInput.clean_email)r   r   r   rz   rB   r   r   r?   r   r{      s    r{   c                       s(   e Zd ZejddZ fddZ  ZS )MarkAsPrimaryEmailInputTr"   c                    r|   )Nunverified_primary_email)r*   rz   r   r~   can_mark_as_primaryr   r3   ry   r?   r   r   rz      r   z#MarkAsPrimaryEmailInput.clean_email)r   r   r   r   BooleanFieldprimaryrz   rB   r   r   r?   r   r      s    r   c                   @   rQ   )ReauthenticateInputNrS   r   r   r   r   r      rT   r   c                   @   rQ   )RequestLoginCodeInputNrS   r   r   r   r   r      rT   r   c                   @   rQ   )ConfirmLoginCodeInputNrS   r   r   r   r   r      rT   r   N),django.core.exceptionsr   django.core.validatorsr   allauth.accountr   r,   allauth.account.adapterr   r   allauth.account.formsr   r   r   r	   r
   r   r   allauth.account.internalr   allauth.account.modelsr   r   r   allauth.corer   allauth.headless.adapter!allauth.headless.internal.restkitr   Inputr   r!   rC   rR   rV   rf   rh   rs   rt   r{   r   r   r   r   r   r   r   r   <module>   s0    $	@
