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
mZ d dlmZ d dlmZ defd	d
ZdefddZdee fddZdee fddZdS )    )Optional)messages)get_adapter)"raise_if_reauthentication_required)app_settingssignals)Authenticator)RecoveryCodesreturnc                 C   s   t jj| djt jjd S )Nuser)type)r   objectsfilterexcludeTypeRECOVERY_CODESexistsr    r   `/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/mfa/recovery_codes/internal/flows.pycan_generate_recovery_codes   s
   r   c                 C   st   t |  tjj| jtjjd  t	| j}|j
}t| }|| tjd tjjt| | j|d |d| j |S )Nr   r   )mfa/messages/recovery_codes_generated.txtsenderrequestr   authenticatorz"mfa/email/recovery_codes_generated)r   r   r   r   r   r   r   deleter	   activateinstanceget_account_adapteradd_messager   SUCCESSr   authenticator_resetsendsend_notification_mail)r   rc_authr   adapterr   r   r   generate_recovery_codes   s&   
r(   c                 C   s.   t jj| jt jjd }|sd S t|  |S )Nr   )r   r   r   r   r   r   firstr   )r   r   r   r   r   view_recovery_codes+   s   r*   c                 C   sv   t jjtjvr	dS t jj| jt jjd }|rdS t	
| j}tjjt | | j|jd t| }|| tjd |jS )zAutomatically (implicitly) setup recovery codes when another
    authenticator is setup for. As this is part of setting up another (primary)
    authenticator, we do not send a notification email in this case.
    Nr   r   r   )r   r   r   r   SUPPORTED_TYPESr   r   r   r   r	   r   r   authenticator_addedr$   r   r    r!   r   r"   )r   has_rcrcr'   r   r   r   auto_generate_recovery_codes6   s*   
r/   N)typingr   django.contribr   allauth.account.adapterr   r    /allauth.account.internal.flows.reauthenticationr   allauth.mfar   r   allauth.mfa.modelsr   (allauth.mfa.recovery_codes.internal.authr	   boolr   r(   r*   r/   r   r   r   r   <module>   s    