
    g                        d dl mZ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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edededefdZ de!dedefdZ"de!dedeeee   f   fdZ#	 d"de!dededeeee   f   fdZ$dee   ddfdZ%defdZ&dedefdZ'dedefdZ(dedefd Z)dede!fd!Z*y)#    )IterableOptionalTuple)messages)HttpRequest)get_adapter)get_authentication_records)flows)"raise_if_reauthentication_required)Login)signals)delete_and_cleanuppost_authentication)Authenticator)auto_generate_recovery_codes)authrequestpasswordlesssignupreturnc                 L    |st        |        t        j                  ||      }|S N)r   r   begin_registration)r   userr   r   creation_optionss        `/var/www/django_project/virt/lib/python3.12/site-packages/allauth/mfa/webauthn/internal/flows.pyr   r      s(     *73..t\B    name
credentialc                 ,    t        | |||d      \  }}|S )NT)r   )_signup_or_add_authenticator)r   r   r   r   authenticatorrc_authenticators         r   signup_authenticatorr$   "   s%    &BtZ'#M# r   c                 L    t        |        t        | | j                  ||d      S )NF)r   r   r   r   )r   r!   r   )r   r   r   s      r   add_authenticatorr&   )   s,     'w/'\\ r   c                 L   t         j                  j                  |||      j                  }t        j
                  j                  t        | ||       t        |       }|j                  | t        j                  d       |s|j                  d|       d }|st        |       }||fS )N)senderr   r   r"   zmfa/messages/webauthn_added.txtzmfa/email/webauthn_added)r   WebAuthnaddinstancer   authenticator_addedsendr   get_account_adapteradd_messager   SUCCESSsend_notification_mailr   )r   r   r   r   r   r"   adapterr#   s           r   r!   r!   6   s     MM%% h	 
 $$#	 %  "'*G!1!13TU&&'A4H7@***r   authenticatorsNc                 @    t        |        |D ]  }t        | |        y r   )r   remove_authenticator)r   r3   r"   s      r   remove_authenticatorsr6   R   s#    &w/' 5Wm45r   r"   c                     t        |        t        | |       t        |       }|j                  | t        j
                  d       |j                  d| j                         y )Nz!mfa/messages/webauthn_removed.txtzmfa/email/webauthn_removed)r   r   r.   r/   r   r0   r1   r   )r   r"   r2   s      r   r5   r5   X   sL    &w/w.!'*G!1!13VW""#?Nr   loginc                 ^    t        | |d       t        j                  j                  | |      S )NT)r   )r   r
   r8   perform_login)r   r"   r8   s      r   perform_passwordless_loginr;   `   s%    TB;;$$We44r   c                 <    t        |       }t        d |D              S )Nc              3      K   | ]9  }|j                  d       |j                  d      |j                  d      fdk(   ; yw)methodtyper   )mfawebauthnTN)get).0records     r   	<genexpr>z-did_use_passwordless_login.<locals>.<genexpr>g   sD        
H	vzz&16::n3MN$	%s   ?A)r	   any)r   recordss     r   did_use_passwordless_loginrH   e   s(    (1G    r   c                      t        | |d       y )NT)reauthenticated)r   )r   r"   s     r   reauthenticaterK   n   s    Er   c                 h    t        |        |j                         }||_        |j                          y r   )r   wrapr   save)r   r"   r   wrappers       r   rename_authenticatorrP   r   s+    &w/  "GGLr   )F)+typingr   r   r   django.contribr   django.httpr   allauth.account.adapterr   r.   allauth.account.authenticationr	   allauth.account.internalr
   /allauth.account.internal.flows.reauthenticationr   allauth.account.modelsr   allauth.mfar   allauth.mfa.base.internal.flowsr   r   allauth.mfa.modelsr   )allauth.mfa.recovery_codes.internal.flowsr   allauth.mfa.webauthn.internalr   booldictr   strr$   r&   r!   r6   r5   r;   rH   rK   rP    r   r   <module>rb      sc   , , # # F E * )  - / DI.2<@	c t  

$(

=(=112
$ + + 	+
 + =(=112+858M3J 5t 5O O5} 5U 5
  FK F F c r   