o
    h                     @   s  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dZ de!dedefddZ"de!dedeeee f fddZ#	d-de!dededeeee f fddZ$dee ddfdd Z%d!efd"d#Z&d!ed$efd%d&Z'dedefd'd(Z(ded!efd)d*Z)d!ede!fd+d,Z*dS ).    )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)authFrequestpasswordlesssignupreturnc                 C   s   |st |  t||}|S N)r
   r   begin_registration)r   userr   r   creation_options r   Z/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/mfa/webauthn/internal/flows.pyr      s   r   name
credentialc                 C   s   t | |||dd\}}|S )NT)r   )_signup_or_add_authenticator)r   r   r   r   authenticatorrc_authenticatorr   r   r   signup_authenticator   s   

r!   c                 C   s   t |  t| | j||ddS )NF)r   r   r   r   )r
   r   r   )r   r   r   r   r   r   add_authenticator$   s   r"   c                 C   sf   t j|||j}tjjt| ||d t| }|	| t
jd |s'|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    r   r   r   r   1   s*   r   authenticatorsNc                 C   s    t |  |D ]}t| | qd S r   )r
   remove_authenticator)r   r.   r   r   r   r   remove_authenticatorsM   s   r0   r   c                 C   s<   t |  t| | t| }|| tjd |d| j d S )Nz!mfa/messages/webauthn_removed.txtzmfa/email/webauthn_removed)r
   r   r)   r*   r   r+   r,   r   )r   r   r-   r   r   r   r/   S   s
   
r/   loginc                 C   s   t | |dd tj| |S )NT)r   )r   r	   r1   perform_login)r   r   r1   r   r   r   perform_passwordless_login[   s   r3   c                 C   s   t | }tdd |D S )Nc                 s   s0    | ]}| d | d| dfdkV  qdS )methodtyper   )mfawebauthnTN)get).0recordr   r   r   	<genexpr>b   s    
z-did_use_passwordless_login.<locals>.<genexpr>)r   any)r   recordsr   r   r   did_use_passwordless_login`   s   r>   c                 C   s   t | |dd d S )NT)reauthenticated)r   )r   r   r   r   r   reauthenticatei   s   r@   c                 C   s"   t |  | }||_|  d S r   )r
   wrapr   save)r   r   r   wrapperr   r   r   rename_authenticatorm   s   rD   )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   r0   r/   r3   r>   r@   rD   r   r   r   r   <module>   s^    
	

	