o
    ×èFhõC  ã                   @   sr   d Z ddlZddlZddlmZ dd„ ZG dd„ dƒZG dd	„ d	ƒZG d
d„ dƒZG dd„ dƒZ	G dd„ dƒZ
dS )z Firebase user import sub module.é    N)Ú_auth_utilsc                 C   s   t  | ¡ ¡ S ©N)Úbase64Úurlsafe_b64encodeÚdecode)Úbytes_value© r   úT/var/www/html/loop/nvenv/lib/python3.10/site-packages/firebase_admin/_user_import.pyÚ
b64_encode   s   r
   c                   @   s¤   e Zd ZdZddd„Zedd„ ƒZejdd„ ƒZedd	„ ƒZejd
d	„ ƒZedd„ ƒZ	e	jdd„ ƒZ	edd„ ƒZ
e
jdd„ ƒZ
edd„ ƒZejdd„ ƒZdd„ ZdS )ÚUserProvideraD  Represents a user identity provider that can be associated with a Firebase user.

    One or more providers can be specified in an ``ImportUserRecord`` when importing users via
    ``auth.import_users()``.

    Args:
        uid: User's unique ID assigned by the identity provider.
        provider_id: ID of the identity provider. This can be a short domain name or the identifier
            of an OpenID identity provider.
        email: User's email address (optional).
        display_name: User's display name (optional).
        photo_url: User's photo URL (optional).
    Nc                 C   s"   || _ || _|| _|| _|| _d S r   )ÚuidÚprovider_idÚemailÚdisplay_nameÚ	photo_url)Úselfr   r   r   r   r   r   r   r	   Ú__init__*   s
   
zUserProvider.__init__c                 C   ó   | j S r   ©Ú_uid©r   r   r   r	   r   1   ó   zUserProvider.uidc                 C   ó   t j|dd�| _d S ©NT©Úrequired©r   Úvalidate_uidr   ©r   r   r   r   r	   r   5   ó   c                 C   r   r   )Ú_provider_idr   r   r   r	   r   9   r   zUserProvider.provider_idc                 C   r   r   )r   Úvalidate_provider_idr    )r   r   r   r   r	   r   =   r   c                 C   r   r   ©Ú_emailr   r   r   r	   r   A   r   zUserProvider.emailc                 C   ó   t  |¡| _d S r   ©r   Úvalidate_emailr#   ©r   r   r   r   r	   r   E   ó   c                 C   r   r   ©Ú_display_namer   r   r   r	   r   I   r   zUserProvider.display_namec                 C   r$   r   ©r   Úvalidate_display_namer*   ©r   r   r   r   r	   r   M   r(   c                 C   r   r   ©Ú
_photo_urlr   r   r   r	   r   Q   r   zUserProvider.photo_urlc                 C   r$   r   ©r   Úvalidate_photo_urlr/   ©r   r   r   r   r	   r   U   r(   c                 C   s,   | j | j| j| j| jdœ}dd„ | ¡ D ƒS )N)ÚrawIdÚ
providerIdÚdisplayNamer   ÚphotoUrlc                 S   ó   i | ]\}}|d ur||“qS r   r   ©Ú.0ÚkÚvr   r   r	   Ú
<dictcomp>a   ó    z(UserProvider.to_dict.<locals>.<dictcomp>)r   r   r   r   r   Úitems©r   Úpayloadr   r   r	   Úto_dictY   s   ûzUserProvider.to_dict)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   Úsetterr   r   r   r   rA   r   r   r   r	   r      s0    










r   c                   @   s,  e Zd ZdZ			d%dd„Zedd„ ƒZejdd„ ƒZedd	„ ƒZejd
d	„ ƒZedd„ ƒZ	e	jdd„ ƒZ	edd„ ƒZ
e
jdd„ ƒZ
edd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZed d!„ ƒZejd"d!„ ƒZd#d$„ ZdS )&ÚImportUserRecordar  Represents a user account to be imported to Firebase Auth.

    Must specify the ``uid`` field at a minimum. A sequence of ``ImportUserRecord`` objects can be
    passed to the ``auth.import_users()`` function, in order to import those users into Firebase
    Auth in bulk. If the ``password_hash`` is set on a user, a hash configuration must be
    specified when calling ``import_users()``.

    Args:
        uid: User's unique ID. Must be a non-empty string not longer than 128 characters.
        email: User's email address (optional).
        email_verified: A boolean indicating whether the user's email has been verified (optional).
        display_name: User's display name (optional).
        phone_number: User's phone number (optional).
        photo_url: User's photo URL (optional).
        disabled: A boolean indicating whether this user account has been disabled (optional).
        user_metadata: An ``auth.UserMetadata`` instance with additional user metadata (optional).
        provider_data: A list of ``auth.UserProvider`` instances (optional).
        custom_claims: A ``dict`` of custom claims to be set on the user account (optional).
        password_hash: User's password hash as a ``bytes`` sequence (optional).
        password_salt: User's password salt as a ``bytes`` sequence (optional).

    Raises:
        ValueError: If provided arguments are invalid.
    Nc                 C   sL   || _ || _|| _|| _|| _|| _|| _|| _|| _|| _	|	| _
|
| _d S r   )r   r   r   Úphone_numberr   Úpassword_hashÚpassword_saltÚemail_verifiedÚdisabledÚuser_metadataÚprovider_dataÚcustom_claims)r   r   r   rL   r   rI   r   rM   rN   rO   rP   rJ   rK   r   r   r	   r   ~   s   
zImportUserRecord.__init__c                 C   r   r   r   r   r   r   r	   r   Ž   r   zImportUserRecord.uidc                 C   r   r   r   r   r   r   r	   r   ’   r   c                 C   r   r   r"   r   r   r   r	   r   –   r   zImportUserRecord.emailc                 C   r$   r   r%   r'   r   r   r	   r   š   r(   c                 C   r   r   r)   r   r   r   r	   r   ž   r   zImportUserRecord.display_namec                 C   r$   r   r+   r-   r   r   r	   r   ¢   r(   c                 C   r   r   )Ú_phone_numberr   r   r   r	   rI   ¦   r   zImportUserRecord.phone_numberc                 C   r$   r   )r   Úvalidate_phonerQ   )r   rI   r   r   r	   rI   ª   r(   c                 C   r   r   r.   r   r   r   r	   r   ®   r   zImportUserRecord.photo_urlc                 C   r$   r   r0   r2   r   r   r	   r   ²   r(   c                 C   r   r   )Ú_password_hashr   r   r   r	   rJ   ¶   r   zImportUserRecord.password_hashc                 C   ó   t  |d¡| _d S )NrJ   )r   Úvalidate_bytesrS   )r   rJ   r   r   r	   rJ   º   ó   c                 C   r   r   )Ú_password_saltr   r   r   r	   rK   ¾   r   zImportUserRecord.password_saltc                 C   rT   )NrK   )r   rU   rW   )r   rK   r   r   r	   rK   Â   rV   c                 C   r   r   )Ú_user_metadatar   r   r   r	   rN   Æ   r   zImportUserRecord.user_metadatac                 C   sJ   |d ur|j nd }|d ur|jnd }t |d¡| _t |d¡| _|| _d S )NÚcreation_timestampÚlast_sign_in_timestamp)rY   rZ   r   Úvalidate_timestampÚ_created_atÚ_last_login_atrX   )r   rN   Ú
created_atÚlast_login_atr   r   r	   rN   Ê   s   ÿ
c                 C   r   r   )Ú_provider_datar   r   r   r	   rO   Ó   r   zImportUserRecord.provider_datac                 C   sH   |d urzt dd„ |D ƒƒrtdƒ‚W n ty   tdƒ‚w || _d S )Nc                 S   s   g | ]}t |tƒ ‘qS r   )Ú
isinstancer   ©r9   Úpr   r   r	   Ú
<listcomp>Û   s    z2ImportUserRecord.provider_data.<locals>.<listcomp>z0One or more provider data instances are invalid.zprovider_data must be iterable.)ÚanyÚ
ValueErrorÚ	TypeErrorr`   )r   rO   r   r   r	   rO   ×   s   ÿÿ
c                 C   r   r   )Ú_custom_claimsr   r   r   r	   rP   á   r   zImportUserRecord.custom_claimsc                 C   s.   t |tƒr
t |¡n|}t |¡| _|| _d S r   )ra   ÚdictÚjsonÚdumpsr   Úvalidate_custom_claimsÚ_custom_claims_strrh   )r   rP   Újson_claimsr   r   r	   rP   å   s   ÿÿ
c                 C   s¢   | j | j| j| j| j| jdurt| jƒnd| jdurt| jƒnd| j| j	| j
| jr.t| jƒnd| jr7t| jƒnddœ}| jrHdd„ | jD ƒ|d< dd„ | ¡ D ƒS )zAReturns a dict representation of the user. For internal use only.N)ÚlocalIdr   r5   ÚphoneNumberr6   ÚemailVerifiedrM   ÚcustomAttributesÚ	createdAtÚlastLoginAtÚpasswordHashÚsaltc                 S   s   g | ]}|  ¡ ‘qS r   )rA   rb   r   r   r	   rd   þ   ó    z,ImportUserRecord.to_dict.<locals>.<listcomp>ÚproviderUserInfoc                 S   r7   r   r   r8   r   r   r	   r<   ÿ   r=   z,ImportUserRecord.to_dict.<locals>.<dictcomp>)r   r   r   rI   r   rL   ÚboolrM   rm   r\   r]   rJ   r
   rK   rO   r>   r?   r   r   r	   rA   ì   s$   

ÿózImportUserRecord.to_dict)NNNNNNNNNNN)rB   rC   rD   rE   r   rF   r   rG   r   r   rI   r   rJ   rK   rN   rO   rP   rA   r   r   r   r	   rH   d   s^    
þ

















	

rH   c                   @   sÌ   e Zd ZdZd#dd„Zdd„ Zedd„ ƒZed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed#dd„ƒZedd „ ƒZed!d"„ ƒZdS )$ÚUserImportHasha‰  Represents a hash algorithm used to hash user passwords.

    An instance of this class must be specified when importing users with passwords via the
    ``auth.import_users()`` API. Use one of the provided class methods to obtain new
    instances when required. Refer to `documentation`_ for more details.

    .. _documentation: https://firebase.google.com/docs/auth/admin/import-users
    Nc                 C   s   || _ || _d S r   )Ú_nameÚ_data)r   ÚnameÚdatar   r   r	   r     s   
zUserImportHash.__init__c                 C   s    d| j i}| jr| | j¡ |S )NÚhashAlgorithm)r{   r|   Úupdater?   r   r   r	   rA     s   
zUserImportHash.to_dictc                 C   s"   dt tj|ddd�ƒi}t||ƒS )NÚ	signerKeyÚkeyTr   )r
   r   rU   rz   )Úclsr}   r‚   r~   r   r   r	   Ú_hmac  s   ÿ
zUserImportHash._hmacc                 C   ó   |   d|¡S )z½Creates a new HMAC SHA512 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚHMAC_SHA512©r„   ©rƒ   r‚   r   r   r	   Úhmac_sha512  ó   
zUserImportHash.hmac_sha512c                 C   r…   )z½Creates a new HMAC SHA256 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚHMAC_SHA256r‡   rˆ   r   r   r	   Úhmac_sha256)  rŠ   zUserImportHash.hmac_sha256c                 C   r…   )z»Creates a new HMAC SHA1 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        Ú	HMAC_SHA1r‡   rˆ   r   r   r	   Ú	hmac_sha15  rŠ   zUserImportHash.hmac_sha1c                 C   r…   )zºCreates a new HMAC MD5 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚHMAC_MD5r‡   rˆ   r   r   r	   Úhmac_md5A  rŠ   zUserImportHash.hmac_md5c              	   C   ó   t ddt |ddd¡iƒS )zÒCreates a new MD5 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚMD5Úroundsr   é    ©rz   r   Úvalidate_int©rƒ   r“   r   r   r	   Úmd5M  ó   
þzUserImportHash.md5c              	   C   r‘   )zÓCreates a new SHA1 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚSHA1r“   é   r”   r•   r—   r   r   r	   Úsha1[  r™   zUserImportHash.sha1c              	   C   r‘   )zÕCreates a new SHA256 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚSHA256r“   r›   r”   r•   r—   r   r   r	   Úsha256i  r™   zUserImportHash.sha256c              	   C   r‘   )zÕCreates a new SHA512 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚSHA512r“   r›   r”   r•   r—   r   r   r	   Úsha512w  r™   zUserImportHash.sha512c              	   C   r‘   )zÛCreates a new PBKDF SHA1 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 120000.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        Ú
PBKDF_SHA1r“   r   éÀÔ r•   r—   r   r   r	   Ú
pbkdf_sha1…  r™   zUserImportHash.pbkdf_sha1c              	   C   r‘   )zÞCreates a new PBKDF2 SHA256 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 120000.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚPBKDF2_SHA256r“   r   r¢   r•   r—   r   r   r	   Úpbkdf2_sha256“  r™   zUserImportHash.pbkdf2_sha256c                 C   sV   t tj|ddd�ƒt |ddd¡t |ddd¡d	œ}|r&t t |d
¡ƒ|d< td|ƒS )a$  Creates a new Scrypt algorithm instance.

        This is the modified Scrypt algorithm used by Firebase Auth. See ``standard_scrypt()``
        function for the standard Scrypt algorith,

        Args:
            key: Signer key as a byte sequence.
            rounds: Number of rounds. Must be an integer between 1 and 8.
            memory_cost: Memory cost as an integer between 1 and 14.
            salt_separator: Salt separator as a byte sequence (optional).

        Returns:
            UserImportHash: A new ``UserImportHash``.
        r‚   Tr   r“   r›   é   Úmemory_costé   )r�   r“   Ú
memoryCostÚsalt_separatorÚsaltSeparatorÚSCRYPT)r
   r   rU   r–   rz   )rƒ   r‚   r“   r§   rª   r~   r   r   r	   Úscrypt¡  s   ý
ÿ
zUserImportHash.scryptc                 C   s   t dƒS )zyCreates a new Bcrypt algorithm instance.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚBCRYPT)rz   )rƒ   r   r   r	   Úbcrypt»  s   zUserImportHash.bcryptc                 C   sH   t j|ddd�t j|ddd�t j|ddd�t j|ddd�dœ}td|ƒS )	a©  Creates a new standard Scrypt algorithm instance.

        Args:
            memory_cost: CPU Memory cost as a non-negative integer.
            parallelization: Parallelization as a non-negative integer.
            block_size: Block size as a non-negative integer.
            derived_key_length: Derived key length as a non-negative integer.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        r§   r   )ÚlowÚparallelizationÚ
block_sizeÚderived_key_length)Ú
cpuMemCostr±   Ú	blockSizeÚdkLenÚSTANDARD_SCRYPT)r   r–   rz   )rƒ   r§   r±   r²   r³   r~   r   r   r	   Ústandard_scryptÄ  s   ü
zUserImportHash.standard_scryptr   )rB   rC   rD   rE   r   rA   Úclassmethodr„   r‰   rŒ   rŽ   r�   r˜   rœ   rž   r    r£   r¥   r­   r¯   r¸   r   r   r   r	   rz     s@    
	











rz   c                   @   s0   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdS )	Ú	ErrorInfoz‡Represents an error encountered while performing a batch operation such
    as importing users or deleting multiple user accounts.
    c                 C   s   |d | _ |d | _d S )NÚindexÚmessage)Ú_indexÚ_reason)r   Úerrorr   r   r	   r   â  s   
zErrorInfo.__init__c                 C   r   r   )r½   r   r   r   r	   r»   æ  r   zErrorInfo.indexc                 C   r   r   )r¾   r   r   r   r	   Úreasonê  r   zErrorInfo.reasonN)rB   rC   rD   rE   r   rF   r»   rÀ   r   r   r   r	   rº   Ú  s    
rº   c                   @   s<   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZd
S )ÚUserImportResultzrRepresents the result of a bulk user import operation.

    See ``auth.import_users()`` API for more details.
    c                 C   s8   |  dg ¡}|t|ƒ | _t|ƒ| _dd„ |D ƒ| _d S )Nr¿   c                 S   s   g | ]}t |ƒ‘qS r   )rº   )r9   Úerrr   r   r	   rd   ù  rw   z-UserImportResult.__init__.<locals>.<listcomp>)ÚgetÚlenÚ_success_countÚ_failure_countÚ_errors)r   ÚresultÚtotalÚerrorsr   r   r	   r   õ  s   
zUserImportResult.__init__c                 C   r   )z2Returns the number of users successfully imported.)rÅ   r   r   r   r	   Úsuccess_countû  ó   zUserImportResult.success_countc                 C   r   )z7Returns the number of users that failed to be imported.)rÆ   r   r   r   r	   Úfailure_count   rÌ   zUserImportResult.failure_countc                 C   r   )zQReturns a list of ``auth.ErrorInfo`` instances describing the errors encountered.)rÇ   r   r   r   r	   rÊ     rÌ   zUserImportResult.errorsN)	rB   rC   rD   rE   r   rF   rË   rÍ   rÊ   r   r   r   r	   rÁ   ï  s    

rÁ   )rE   r   rj   Úfirebase_adminr   r
   r   rH   rz   rº   rÁ   r   r   r   r	   Ú<module>   s   I  Y