U
    M+|jÑ  ã                   @   sœ   d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ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)Úcheck_passwordÚis_password_usableÚmake_password)Úmodels)Úget_random_stringÚsalted_hmac)ÚRemovedInDjango51Warning)Úgettext_lazyc                   @   s*   e Zd Zedd„ ƒZd
dd„Zdd„ Zd	S )ÚBaseUserManagerc                 C   sJ   |pd}z|  ¡  dd¡\}}W n tk
r4   Y nX |d | ¡  }|S )zS
        Normalize the email address by lowercasing the domain part of it.
        Ú ú@é   )ÚstripÚrsplitÚ
ValueErrorÚlower)ÚclsÚemailZ
email_nameZdomain_part© r   úec:\users\snmko\desktop\web_content\django_cbt\venv\Lib\site-packages\django/contrib/auth/base_user.pyÚnormalize_email   s    zBaseUserManager.normalize_emailé
   Ú7abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789c                 C   s   t jdtdd� t||ƒS )zë
        Generate a random password with the given length and given
        allowed_chars. The default value of allowed_chars does not have "I" or
        "O" or letters and digits that look similar -- just to avoid confusion.
        z5BaseUserManager.make_random_password() is deprecated.é   )ÚcategoryÚ
stacklevel)ÚwarningsÚwarnr
   r   )ÚselfÚlengthÚallowed_charsr   r   r   Úmake_random_password$   s    
ýz$BaseUserManager.make_random_passwordc                 C   s   | j f | jj|iŽS ©N)ÚgetÚmodelÚUSERNAME_FIELD)r    Úusernamer   r   r   Úget_by_natural_key5   s    z"BaseUserManager.get_by_natural_keyN)r   r   )Ú__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$d%„Zed&d'„ ƒZed(d)„ ƒZ‡  ZS )+ÚAbstractBaseUserÚpasswordé€   )Ú
max_lengthz
last loginT)ZblankÚnullNc                   @   s   e Zd ZdZdS )zAbstractBaseUser.MetaTN)r*   r+   r,   Zabstractr   r   r   r   ÚMetaE   s   r3   c                 C   s   |   ¡ S r$   ©Úget_username©r    r   r   r   Ú__str__H   s    zAbstractBaseUser.__str__c                    s0   t ƒ j||Ž | jd k	r,t | j| ¡ d | _d S r$   )ÚsuperÚsaveÚ	_passwordr   Zpassword_changed)r    ÚargsÚkwargs©Ú	__class__r   r   r9   K   s    
zAbstractBaseUser.savec                 C   s   t | | jƒS )z"Return the username for this User.)Úgetattrr'   r6   r   r   r   r5   Q   s    zAbstractBaseUser.get_usernamec                 C   s   t | | j|  |  ¡ ¡ƒ d S r$   )Úsetattrr'   Únormalize_usernamer5   r6   r   r   r   ÚcleanU   s    zAbstractBaseUser.cleanc                 C   s
   |   ¡ fS r$   r4   r6   r   r   r   Únatural_keyX   s    zAbstractBaseUser.natural_keyc                 C   s   dS )zj
        Always return False. This is a way of comparing User objects to
        anonymous users.
        Fr   r6   r   r   r   Úis_anonymous[   s    zAbstractBaseUser.is_anonymousc                 C   s   dS )zt
        Always return True. This is a way to tell if the user has been
        authenticated in templates.
        Tr   r6   r   r   r   Úis_authenticatedc   s    z!AbstractBaseUser.is_authenticatedc                 C   s   t |ƒ| _|| _d S r$   )r   r/   r:   )r    Úraw_passwordr   r   r   Úset_passwordk   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/   )Zupdate_fields)rG   r:   r9   )rF   r6   r   r   Úsetteru   s    
z/AbstractBaseUser.check_password.<locals>.setter)r   r/   )r    rF   rH   r   r6   r   r   o   s    zAbstractBaseUser.check_passwordc                 C   s   t d ƒ| _d S r$   )r   r/   r6   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/   r6   r   r   r   Úhas_usable_password�   s    z$AbstractBaseUser.has_usable_passwordc                 C   s   |   ¡ S )z7
        Return an HMAC of the password field.
        )Ú_get_session_auth_hashr6   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   ZSECRET_KEY_FALLBACKSrK   )r    Z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)rM   Ú	algorithm)r	   r/   Ú	hexdigest)r    rM   Zkey_saltr   r   r   rK   ‘   s    üz'AbstractBaseUser._get_session_auth_hashc                 C   s$   z| j W S  tk
r   Y dS X d S )Nr   )Z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   rA   ¡   s    ÿýz#AbstractBaseUser.normalize_username)N) r*   r+   r,   r   Z	CharFieldÚ_r/   ZDateTimeFieldZ
last_loginZ	is_activeZREQUIRED_FIELDSr:   r3   r7   r9   r5   rB   rC   ÚpropertyrD   rE   rG   r   rI   rJ   rL   rN   rK   r-   rS   rA   Ú__classcell__r   r   r=   r   r.   9   s4   


	
r.   )Ú__doc__rW   r   Zdjango.confr   Zdjango.contrib.authr   Zdjango.contrib.auth.hashersr   r   r   Z	django.dbr   Zdjango.utils.cryptor   r	   Zdjango.utils.deprecationr
   Zdjango.utils.translationr   rY   ÚManagerr   ZModelr.   r   r   r   r   Ú<module>   s   $