o
    úLf®
  ã                   @   sr   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 G dd„ dƒZd	d
„ ZdS )é    )Úgettext_lazy)Úapp_settings)Úget_adapter)Ú
user_emailÚuser_username)Úcontext)Úimport_attributec                   @   s€   e Zd ZdZedƒedƒedƒedƒdœZ	 de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d„ Zdd„ ZdS )ÚDefaultMFAAdaptera3  The adapter class allows you to override various functionality of the
    ``allauth.mfa`` app.  To do so, point ``settings.MFA_ADAPTER`` to your own
    class that derives from ``DefaultMFAAdapter`` and override the behavior by
    altering the implementation of the methods according to your own need.
    zYYou cannot activate two-factor authentication until you have verified your email address.zUYou cannot add an email address to an account protected by two-factor authentication.zIncorrect code.z0You cannot deactivate two-factor authentication.)Úunverified_emailÚadd_email_blockedÚincorrect_codeÚcannot_delete_authenticatorÚreturnc                 C   s$   t |ƒ}|s
t|ƒ}|st|ƒ}|S )zZReturns the label used for representing the given user in a TOTP QR
        code.
        )r   r   Ústr)ÚselfÚuserÚlabel© r   úT/var/www/html/humari/django-venv/lib/python3.10/site-packages/allauth/mfa/adapter.pyÚget_totp_label    s   z DefaultMFAAdapter.get_totp_labelc                 C   s>   t j}|stjrddlm} |j tj	¡j
}|S tj	 ¡ }|S )zYReturns the TOTP issuer name that will be contained in the TOTP QR
        code.
        r   )ÚSite)r   ÚTOTP_ISSUERÚallauth_settingsÚSITES_ENABLEDÚdjango.contrib.sites.modelsr   ÚobjectsÚget_currentr   ÚrequestÚnameÚget_host)r   Úissuerr   r   r   r   Úget_totp_issuer+   s   
ÿz!DefaultMFAAdapter.get_totp_issuerÚtextc                 C   s   |S )z³Secrets such as the TOTP key are stored in the database.  This
        hook can be used to encrypt those so that they are not stored in the
        clear in the database.
        r   )r   r"   r   r   r   Úencrypt9   s   zDefaultMFAAdapter.encryptÚencrypted_textc                 C   s   |}|S )zCounter part of ``encrypt()``.r   )r   r$   r"   r   r   r   Údecrypt@   s   zDefaultMFAAdapter.decryptc                 C   s   dS )NTr   )r   Úauthenticatorr   r   r   Úcan_delete_authenticatorE   s   z*DefaultMFAAdapter.can_delete_authenticatorc                 O   s   t ƒ j|i |¤ŽS ©N)Úget_account_adapterÚsend_notification_mail)r   ÚargsÚkwargsr   r   r   r*   H   s   z(DefaultMFAAdapter.send_notification_mailN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_Úerror_messagesr   r   r!   r#   r%   r'   r*   r   r   r   r   r	      s(    ÿÿÿør	   c                   C   s   t tjƒƒ S r(   )r   r   ÚADAPTERr   r   r   r   r   L   s   r   N)Údjango.utils.translationr   r1   Úallauthr   r   Úallauth.account.adapterr   r)   Úallauth.account.utilsr   r   Úallauth.corer   Úallauth.mfaÚallauth.utilsr   r	   r   r   r   r   Ú<module>   s    A