Ë
    ûûàg÷  ã                   óÒ   — 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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  G d„ de«      Z de fd„Zy)é    )ÚBytesIO)ÚDict)Úquote)Ú	urlencode)ÚgettextÚgettext_lazy)Úapp_settings)Úget_adapter)Úuser_displayÚ
user_emailÚuser_pk_to_url_strÚuser_username)Úcontext)ÚBaseAdapter)ÚAuthenticator)Úimport_attributec                   ó8  — e Zd ZdZ ed«       ed«       ed«       ed«       ed«      dœZ	 defd	„Zdefd
„Zdefd„Z	dedefd„Z
dede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„ Zddefd„Zdej(                  defd„Zdeeef   fd„Zdefd„Zy)ÚDefaultMFAAdaptera4  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 needs.
    zUYou cannot add an email address to an account protected by two-factor authentication.z0You cannot deactivate two-factor authentication.zTYou cannot generate recovery codes without having two-factor authentication enabled.zIncorrect code.zYYou cannot activate two-factor authentication until you have verified your email address.)Úadd_email_blockedÚcannot_delete_authenticatorÚcannot_generate_recovery_codesÚincorrect_codeÚunverified_emailÚreturnc                 ó$   — | j                  |«      S )zZReturns the label used for representing the given user in a TOTP QR
        code.
        )Ú_get_user_identifier©ÚselfÚusers     úQ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/allauth/mfa/adapter.pyÚget_totp_labelz DefaultMFAAdapter.get_totp_label/   s   € ð ×(Ñ(¨Ó.Ð.ó    c                 óP   — t        |«      }|st        |«      }|st        |«      }|S )z`Human-palatable identifier for a user account. It is intended only
        for display.
        )r   r   Ústr)r   r   Úlabels      r    r   z&DefaultMFAAdapter._get_user_identifier5   s,   € ô ˜4Ó ˆÙÜ! $Ó'ˆEÙÜ˜“IˆEØˆr"   c                 óJ   — t         j                  }|s| j                  «       }|S )zYReturns the TOTP issuer name that will be contained in the TOTP QR
        code.
        )r	   ÚTOTP_ISSUERÚ_get_site_name)r   Úissuers     r    Úget_totp_issuerz!DefaultMFAAdapter.get_totp_issuer@   s%   € ô ×)Ñ)ˆÙØ×(Ñ(Ó*ˆFØˆr"   Úsecretc                 ó  — | j                  |«      }| j                  «       }||dœ}t        j                  dk7  rt        j                  |d<   t        j                  dk7  rt        j                  |d<   dt        |«      › dt        |«      › �S )N)r+   r)   é   Údigitsé   Úperiodzotpauth://totp/ú?)r!   r*   r	   ÚTOTP_DIGITSÚTOTP_PERIODr   r   )r   r   r+   r%   r)   Úparamss         r    Úbuild_totp_urlz DefaultMFAAdapter.build_totp_urlI   sŠ   € Ø×#Ñ# DÓ)ˆØ×%Ñ%Ó'ˆàð ñ	
ˆô ×#Ñ# qÒ(Ü+×7Ñ7ˆF�8ÑÜ×#Ñ# rÒ)Ü+×7Ñ7ˆF�8ÑØ ¤ u£ ¨a´	¸&Ó0AÐ/BÐCÐCr"   Úurlc                 ó°   — dd l }ddlm} |j                  ||¬«      }t	        «       }|j                  |«       |j                  «       j                  d«      S )Nr   )ÚSvgPathImage)Úimage_factoryÚutf8)ÚqrcodeÚqrcode.image.svgr8   Úmaker   ÚsaveÚgetvalueÚdecode)r   r6   r;   r8   ÚimgÚbufs         r    Úbuild_totp_svgz DefaultMFAAdapter.build_totp_svgX   sC   € ÛÝ1à�k‰k˜#¨\ˆkÓ:ˆÜ‹iˆØ�‰�ŒØ�|‰|‹~×$Ñ$ VÓ,Ð,r"   c                 óÐ   — t         j                  r9ddlm} |j                  j                  t        j                  «      j                  S t        j                  j                  «       S )Nr   )ÚSite)
Úallauth_settingsÚSITES_ENABLEDÚdjango.contrib.sites.modelsrE   ÚobjectsÚget_currentr   ÚrequestÚnameÚget_host)r   rE   s     r    r(   z DefaultMFAAdapter._get_site_namea   s@   € Ü×)Ò)Ý8à—<‘<×+Ñ+¬G¯O©OÓ<×AÑAÐAä—?‘?×+Ñ+Ó-Ð-r"   Útextc                 ó   — |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   rN   s     r    ÚencryptzDefaultMFAAdapter.encrypti   s	   € ð
 ˆr"   Úencrypted_textc                 ó
   — |}|S )zCounter part of ``encrypt()``.rP   )r   rR   rN   s      r    ÚdecryptzDefaultMFAAdapter.decryptp   s   € àˆØˆr"   Úauthenticatorc                  ó   — y)NTrP   )r   rU   s     r    Úcan_delete_authenticatorz*DefaultMFAAdapter.can_delete_authenticatoru   s   € Ør"   c                 ó6   —  t        «       j                  |i |¤ŽS ©N)Úget_account_adapterÚsend_notification_mail)r   ÚargsÚkwargss      r    r[   z(DefaultMFAAdapter.send_notification_mailx   s   € Ø;Ô"Ó$×;Ñ;¸TÐLÀVÑLÐLr"   Nc                 ó¤   — |j                   ryt        j                  j                  |¬«      }|�|j                  |¬«      }|j	                  «       S )zM
        Returns ``True`` if (and only if) the user has 2FA enabled.
        F)r   )Útype__in)Úis_anonymousr   rI   ÚfilterÚexists)r   r   ÚtypesÚqss       r    Úis_mfa_enabledz DefaultMFAAdapter.is_mfa_enabled{   sK   € ð ×ÒØÜ×"Ñ"×)Ñ)¨tÐ)Ó4ˆØÐØ—‘ E�Ó*ˆBØ�y‰y‹{Ðr"   Útypec                 óÜ   — t         j                  j                  ||¬«      j                  «       }|dk(  rt	        d«      S |dk(  rt	        d«      S t	        d«      j                  |dz   ¬«      S )zi
        Generate a human friendly name for the key. Used to prefill the "Add
        key" form.
        )r   rf   r   z
Master keyé   z
Backup keyzKey nr. {number})Únumber)r   rI   ra   Úcountr   Úformat)r   r   rf   Úns       r    Úgenerate_authenticator_namez-DefaultMFAAdapter.generate_authenticator_name†   sj   € ô
 ×!Ñ!×(Ñ(¨d¸Ð(Ó>×DÑDÓFˆØ�Š6Ü˜<Ó(Ð(Ø�!ŠVÜ˜<Ó(Ð(ÜÐ)Ó*×1Ñ1¸¸Q¹Ð1Ó?Ð?r"   c                 óˆ   — | j                  «       }t        j                  j                  «       j	                  d«      d   |dœS )Nú:r   )ÚidrL   )r(   r   rK   rM   Ú	partition)r   rL   s     r    Ú#get_public_key_credential_rp_entityz5DefaultMFAAdapter.get_public_key_credential_rp_entity’   s=   € Ø×"Ñ"Ó$ˆä—/‘/×*Ñ*Ó,×6Ñ6°sÓ;¸AÑ>Øñ
ð 	
r"   c                 ón   — t        |«      j                  d«      t        |«      | j                  |«      dœS )Nr:   )rp   Údisplay_namerL   )r   Úencoder   r   r   s     r    Ú%get_public_key_credential_user_entityz7DefaultMFAAdapter.get_public_key_credential_user_entity™   s5   € ä$ TÓ*×1Ñ1°&Ó9Ü(¨Ó.Ø×-Ñ-¨dÓ3ñ
ð 	
r"   rY   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_Úerror_messagesr$   r!   r   r*   r5   rC   r(   rQ   rT   r   ÚboolrW   r[   re   ÚTyperm   r   rr   Údictrv   rP   r"   r    r   r      s1  „ ññ Øcó
ñ ()Ø>ó(
ñ +,Øbó+
ñ Ð-Ó.ÙØgó
ñ€Nð Fð/ có /ð	¨Có 	ð ó ðD¨3ð D°3ó Dð- #ð -¨#ó -ð. ó .ð˜Cð  Có ð cð ¨có ð
°mð Èó òMñ	°$ó 	ð
@°m×6HÑ6Hð 
@ÈSó 
@ð
°T¸#¸s¸(±^ó 
ð
¸Tô 
r"   r   r   c                  ó>   —  t        t        j                  «      «       S rY   )r   r	   ÚADAPTERrP   r"   r    r
   r
   ¡   s   € Ø1ÔœL×0Ñ0Ó1Ó3Ð3r"   N)!Úior   Útypingr   Úurllib.parser   Údjango.utils.httpr   Údjango.utils.translationr   r   r{   Úallauthr	   rF   Úallauth.account.adapterr
   rZ   Úallauth.account.utilsr   r   r   r   Úallauth.corer   Úallauth.core.internal.adapterr   Úallauth.mfaÚallauth.mfa.modelsr   Úallauth.utilsr   r   rP   r"   r    ú<module>r�      sQ   ðÝ Ý Ý å 'ß ?å 4Ý F÷ó õ !Ý 5Ý $Ý ,Ý *ôG
˜ô G
ðT4Ð&ô 4r"   