o
    þÞh³  ã                   @   sˆ   d Z ddl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 G d	d
„ d
ejƒZG dd„ dejƒZdS )zg
This module allows importing AbstractBaseUser even when django.contrib.auth is
not in INSTALLED_APPS.
é    N)Úsettings)Úpassword_validation)Úacheck_passwordÚcheck_passwordÚis_password_usableÚmake_password)Úmodels)Úsalted_hmac)Úgettext_lazyc                   @   s(   e Zd Zedd„ ƒZdd„ Zdd„ ZdS )ÚBaseUserManagerc                 C   sJ   |pd}z|  ¡  dd¡\}}W n
 ty   Y |S w |d | ¡  }|S )zS
        Normalize the email address by lowercasing the domain part of it.
        Ú ú@é   )ÚstripÚrsplitÚ
ValueErrorÚlower)ÚclsÚemailÚ
email_nameÚdomain_part© r   ú]/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/contrib/auth/base_user.pyÚnormalize_email   s   üzBaseUserManager.normalize_emailc                 C   s   | j di | jj|i¤ŽS ©Nr   )ÚgetÚmodelÚUSERNAME_FIELD©ÚselfÚusernamer   r   r   Úget_by_natural_key$   s   z"BaseUserManager.get_by_natural_keyc                 Ã   s    �| j di | jj|i¤ŽI d H S r   )Úagetr   r   r   r   r   r   Úaget_by_natural_key'   s   €z#BaseUserManager.aget_by_natural_keyN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r!   r#   r   r   r   r   r      s
    
r   c                       sî   e Zd Zejedƒdd�Zejedƒddd�ZdZ	g Z
dZG dd	„ d	ƒZd
d„ Z‡ fdd„Zdd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd,d&d'„Zed(d)„ ƒZed*d+„ ƒZ‡  Z S )-ÚAbstractBaseUserÚpasswordé€   )Ú
max_lengthz
last loginT)ÚblankÚnullNc                   @   s   e Zd ZdZdS )zAbstractBaseUser.MetaTN)r$   r%   r&   Úabstractr   r   r   r   ÚMeta7   s    r/   c                 C   ó   |   ¡ S ©N©Úget_username©r   r   r   r   Ú__str__:   s   zAbstractBaseUser.__str__c                    s8   t ƒ j|i |¤Ž | jd urt | j| ¡ d | _d S d S r1   )ÚsuperÚsaveÚ	_passwordr   Úpassword_changed)r   ÚargsÚkwargs©Ú	__class__r   r   r7   @   s
   

þzAbstractBaseUser.savec                 C   s   t | | jƒS )z"Return the username for this User.)Úgetattrr   r4   r   r   r   r3   F   s   zAbstractBaseUser.get_usernamec                 C   s   t | | j|  |  ¡ ¡ƒ d S r1   )Úsetattrr   Únormalize_usernamer3   r4   r   r   r   ÚcleanJ   s   zAbstractBaseUser.cleanc                 C   s
   |   ¡ fS r1   r2   r4   r   r   r   Únatural_keyM   s   
zAbstractBaseUser.natural_keyc                 C   ó   dS )zj
        Always return False. This is a way of comparing User objects to
        anonymous users.
        Fr   r4   r   r   r   Úis_anonymousP   ó   zAbstractBaseUser.is_anonymousc                 C   rC   )zt
        Always return True. This is a way to tell if the user has been
        authenticated in templates.
        Tr   r4   r   r   r   Úis_authenticatedX   rE   z!AbstractBaseUser.is_authenticatedc                 C   s   t |ƒ| _|| _d S r1   )r   r)   r8   )r   Úraw_passwordr   r   r   Úset_password`   s   

zAbstractBaseUser.set_passwordc                    s   ‡ fdd„}t |ˆ j|ƒS )z~
        Return a boolean of whether the raw_password was correct. Handles
        hashing formats behind the scenes.
        c                    s"   ˆ   | ¡ d ˆ _ˆ jdgd� d S ©Nr)   )Úupdate_fields)rH   r8   r7   ©rG   r4   r   r   Úsetterj   s   
z/AbstractBaseUser.check_password.<locals>.setter)r   r)   ©r   rG   rL   r   r4   r   r   d   s   zAbstractBaseUser.check_passwordc                 ƒ   s"   �‡ fdd„}t |ˆ j|ƒI dH S )zSee check_password().c                 “   s*   �ˆ   | ¡ d ˆ _ˆ jdgd�I d H  d S rI   )rH   r8   ÚasaverK   r4   r   r   rL   u   s   €
z0AbstractBaseUser.acheck_password.<locals>.setterN)r   r)   rM   r   r4   r   r   r   s   €z AbstractBaseUser.acheck_passwordc                 C   s   t d ƒ| _d S r1   )r   r)   r4   r   r   r   Úset_unusable_password}   s   z&AbstractBaseUser.set_unusable_passwordc                 C   s
   t | jƒS )zX
        Return False if set_unusable_password() has been called for this user.
        )r   r)   r4   r   r   r   Úhas_usable_password�   s   
z$AbstractBaseUser.has_usable_passwordc                 C   r0   )z7
        Return an HMAC of the password field.
        )Ú_get_session_auth_hashr4   r   r   r   Úget_session_auth_hash‡   s   z&AbstractBaseUser.get_session_auth_hashc                 c   s    � t jD ]	}| j|d�V  qd S )N)Úsecret)r   ÚSECRET_KEY_FALLBACKSrQ   )r   Úfallback_secretr   r   r   Úget_session_auth_fallback_hash�   s   €
ÿz/AbstractBaseUser.get_session_auth_fallback_hashc                 C   s   d}t || j|dd� ¡ S )NzAdjango.contrib.auth.models.AbstractBaseUser.get_session_auth_hashÚsha256)rS   Ú	algorithm)r	   r)   Ú	hexdigest)r   rS   Úkey_saltr   r   r   rQ   ‘   s   üûz'AbstractBaseUser._get_session_auth_hashc                 C   s   z| j W S  ty   Y dS w )Nr   )ÚEMAIL_FIELDÚAttributeError)r   r   r   r   Úget_email_field_nameš   s
   ÿz%AbstractBaseUser.get_email_field_namec                 C   s   t |tƒrt d|¡S |S )NÚNFKC)Ú
isinstanceÚstrÚunicodedataÚ	normalize)r   r    r   r   r   r@   ¡   s
   ÿÿýz#AbstractBaseUser.normalize_usernamer1   )!r$   r%   r&   r   Ú	CharFieldÚ_r)   ÚDateTimeFieldÚ
last_loginÚ	is_activeÚREQUIRED_FIELDSr8   r/   r5   r7   r3   rA   rB   ÚpropertyrD   rF   rH   r   r   rO   rP   rR   rV   rQ   r'   r]   r@   Ú__classcell__r   r   r<   r   r(   +   s8    


	
r(   )Ú__doc__ra   Údjango.confr   Údjango.contrib.authr   Údjango.contrib.auth.hashersr   r   r   r   Ú	django.dbr   Údjango.utils.cryptor	   Údjango.utils.translationr
   rd   ÚManagerr   ÚModelr(   r   r   r   r   Ú<module>   s    