
    fk                        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  G d	 d
ej$                        Z G d dej$                        Z G d de      Z G d de      Z G d dej$                        Zy)    )forms)gettext_lazy)context)app_settings)get_adapter)check_rate_limit)Authenticator)authflowsc                        e Zd Z ej                  d      Zej                  r! ej                   e	d      d e	d            Z
 ej                  dej                        Z fdZd	 Z fd
Z xZS )AddWebAuthnFormFrequiredPasswordlesszEnabling passwordless operation allows you to sign in using just this key, but imposes additional requirements such as biometrics or PIN protection.)labelr   	help_textTr   widgetc                    |j                  d      | _        |j                  di       }|j                  dt               j	                  | j                  t
        j                  j                               t        | $  |i | y )Nuserinitialname)
popr   
setdefaultr   generate_authenticator_namer	   TypeWEBAUTHNsuper__init__selfargskwargsr   	__class__s       U/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/mfa/webauthn/forms.pyr   zAddWebAuthnForm.__init__   so    JJv&	##Ir2M55		=--66	
 	$)&)    c                     | j                   d   }|s<t               j                  | 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   s     r%   
clean_namezAddWebAuthnForm.clean_name#   sE       (=<<		=--66D r&   c                     t         |          }|j                  d      }|r*t        j                  |       t        j
                  |       |S N
credential)r   cleangetr
   parse_registration_responsecomplete_registration)r!   r(   r,   r$   s      r%   r-   zAddWebAuthnForm.clean1   sE    w}!%%l3
 ,,Z8&&z2r&   )__name__
__module____qualname__r   	CharFieldr   r   PASSKEY_LOGIN_ENABLEDBooleanField_passwordless	JSONFieldHiddenInputr,   r   r)   r-   __classcell__r$   s   @r%   r   r      su    5??E*D)))u))N# g
 !$u7H7HIJ	*	 	r&   r   c                   f     e Zd Z ej                  dej
                        Z fdZd Zd Z	 xZ
S )AuthenticateWebAuthnFormTr   c                 P    |j                  d      | _        t        |   |i | y Nr   )r   r   r   r   r!   r"   r#   r$   s      r%   r   z!AuthenticateWebAuthnForm.__init__@   s%    JJv&	$)&)r&   c                     | j                   d   }t        j                  |       | j                  }|t        j                  |      }t        |      }t        j                  ||      } |        |S r+   )r(   r
   parse_authentication_responser   extract_user_from_responser   complete_authentication)r!   r,   r   clear_rlauthenticators        r%   clean_credentialz)AuthenticateWebAuthnForm.clean_credentialD   sg    &&|4
 	**:6yy<22:>D#D)44T:F
r&   c                 B    | j                   d   }|j                          y r+   )r(   record_usage)r!   rG   s     r%   savezAuthenticateWebAuthnForm.saveR   s    )),7""$r&   )r1   r2   r3   r   r9   r:   r,   r   rH   rK   r;   r<   s   @r%   r>   r>   =   s*     $u7H7HIJ*%r&   r>   c                        e Zd Z fdZ xZS )LoginWebAuthnFormc                 (    t        |   |dd i| y r@   )r   r   rA   s      r%   r   zLoginWebAuthnForm.__init__X   s    $4T4V4r&   )r1   r2   r3   r   r;   r<   s   @r%   rM   rM   W   s    5 5r&   rM   c                       e Zd Zy)ReauthenticateWebAuthnFormN)r1   r2   r3    r&   r%   rP   rP   \   s    r&   rP   c                   P     e Zd Z ej                  d      Z fdZdefdZ xZ	S )EditWebAuthnFormTr   c                     |j                  d      | _        |j                  di       }|j                  d| j                  j                         j                         t        |   |i | y )Ninstancer   r   )r   rU   r   wrapr   r   r   r    s       r%   r   zEditWebAuthnForm.__init__c   sZ    

:.##Ir264==#5#5#7#<#<=$)&)r&   returnc                     t        j                  t        j                  | j                  | j
                  d          | j                  S )Nr   )r   rename_authenticatorr   requestrU   r(   )r!   s    r%   rK   zEditWebAuthnForm.savei   s6    ""OOT]]D,=,=f,E	
 }}r&   )
r1   r2   r3   r   r4   r   r   r	   rK   r;   r<   s   @r%   rS   rS   `   s$    5??D)D*m r&   rS   N)djangor   django.utils.translationr   r7   allauth.corer   allauth.mfar   allauth.mfa.adapterr   allauth.mfa.base.internal.flowsr   allauth.mfa.modelsr	   allauth.mfa.webauthn.internalr
   r   Formr   r>   rM   rP   rS   rQ   r&   r%   <module>rd      sh     6   $ + < , 5.ejj .b%uzz %450 5
	!9 	uzz r&   