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 d dlmZ d dlmZm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jZG dd deZG dd deZG dd dejZdS )    )forms)gettext_lazy)context)app_settings)get_adapter)check_rate_limitpost_authentication)Authenticator)authflowsc                       sL   e Zd ZejddZejdejdZ fddZ	dd Z
 fd	d
Z  ZS )_BaseAddWebAuthnFormFrequiredTr   widgetc                    sJ   | d| _|di }|dt | jtjj t j	|i | d S )Nuserinitialname)
popr   
setdefaultr   generate_authenticator_namer	   TypeWEBAUTHNsuper__init__selfargskwargsr   	__class__ Q/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/mfa/webauthn/forms.pyr      s   
z_BaseAddWebAuthnForm.__init__c                 C   s&   | j d }|st | jtjj}|S )a+  
        We don't want to make `name` a required field, as the WebAuthn
        ceremony happens before posting the resulting credential, and we don't
        want to reject a valid credential because of a missing name -- it might
        be resident already. So, gracefully plug in a name.
        r   )cleaned_datar   r   r   r	   r   r   )r   r   r!   r!   r"   
clean_name   s   

z_BaseAddWebAuthnForm.clean_namec                    s0   t   }|d}|rt| t| |S N
credential)r   cleangetr
   parse_registration_responsecomplete_registration)r   r#   r&   r   r!   r"   r'   )   s   



z_BaseAddWebAuthnForm.clean)__name__
__module____qualname__r   	CharFieldr   	JSONFieldHiddenInputr&   r   r$   r'   __classcell__r!   r!   r   r"   r      s    r   c                   @   s.   e Zd ZejrejeddeddZdS dS )AddWebAuthnFormPasswordlessFzEnabling passwordless operation allows you to sign in using just this key, but imposes additional requirements such as biometrics or PIN protection.)labelr   	help_textN)	r+   r,   r-   r   PASSKEY_LOGIN_ENABLEDr   BooleanField_passwordlessr!   r!   r!   r"   r2   5   s    
r2   c                   @   s   e Zd ZdS )SignupWebAuthnFormN)r+   r,   r-   r!   r!   r!   r"   r:   @   s    r:   c                       sD   e Zd ZejdejdZdZdZ fddZ	dd Z
dd	 Z  ZS )
AuthenticateWebAuthnFormTr   Fc                    s"   | d| _t j|i | d S Nr   )r   r   r   r   r   r   r   r   r!   r"   r   I   s   z!AuthenticateWebAuthnForm.__init__c                 C   sJ   | j d }t| | j}|d u rt|}t|}t||}|  |S r%   )r#   r
   parse_authentication_responser   extract_user_from_responser   complete_authentication)r   r&   r   clear_rlauthenticatorr!   r!   r"   clean_credentialM   s   


z)AuthenticateWebAuthnForm.clean_credentialc                 C   s$   | j d }ttj|| j| jd d S )Nr&   )reauthenticatedr9   )r#   r   r   requestrD   r9   )r   rB   r!   r!   r"   save[   s   

zAuthenticateWebAuthnForm.save)r+   r,   r-   r   r/   r0   r&   rD   r9   r   rC   rF   r1   r!   r!   r   r"   r;   D   s    r;   c                       s$   e Zd ZdZdZ fddZ  ZS )LoginWebAuthnFormFTc                    s   t  j|dd i| d S r<   )r   r   r=   r   r!   r"   r   i   s   zLoginWebAuthnForm.__init__)r+   r,   r-   rD   r9   r   r1   r!   r!   r   r"   rG   e   s    rG   c                   @   s   e Zd ZdZdZdS )ReauthenticateWebAuthnFormTFN)r+   r,   r-   rD   r9   r!   r!   r!   r"   rH   m   s    rH   c                       s6   e Zd ZejddZ fddZdefddZ  Z	S )EditWebAuthnFormTr   c                    sB   | d| _|di }|d| j j t j|i | d S )Ninstancer   r   )r   rJ   r   wrapr   r   r   r   r   r!   r"   r   u   s   zEditWebAuthnForm.__init__returnc                 C   s   t tj| j| jd  | jS )Nr   )r   rename_authenticatorr   rE   rJ   r#   )r   r!   r!   r"   rF   {   s   zEditWebAuthnForm.save)
r+   r,   r-   r   r.   r   r   r	   rF   r1   r!   r!   r   r"   rI   r   s    rI   N)djangor   django.utils.translationr   r8   allauth.corer   allauth.mfar   allauth.mfa.adapterr   allauth.mfa.base.internal.flowsr   r   allauth.mfa.modelsr	   allauth.mfa.webauthn.internalr
   r   Formr   r2   r:   r;   rG   rH   rI   r!   r!   r!   r"   <module>   s    )!