

_VV                 @   s   d  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 Gd	 d
   d
 e
 j  Z e Gd d   d e
 j   Z d S)zg
This module allows importing AbstractBaseUser even when django.contrib.auth is
not in INSTALLED_APPS.
    )unicode_literals)password_validation)check_passwordis_password_usablemake_password)models)get_random_stringsalted_hmac)python_2_unicode_compatible)ugettext_lazyc               @   s@   e  Z d  Z e d d    Z d d d d  Z d d   Z d	 S)
BaseUserManagerc             C   sb   | p	 d } y" | j    j d d  \ } } Wn t k
 rB Yn Xd j | | j   g  } | S)zW
        Normalize the email address by lowercasing the domain part of the it.
         @   )striprsplit
ValueErrorjoinlower)clsemailZ
email_nameZdomain_part r   ?/tmp/pip-build-ghmbqnp_/Django/django/contrib/auth/base_user.pynormalize_email   s    "zBaseUserManager.normalize_email
   Z7abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789c             C   s   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.
        )r   )selflengthallowed_charsr   r   r   make_random_password!   s    	z$BaseUserManager.make_random_passwordc             C   s   |  j  i | |  j j 6  S)N)getmodelUSERNAME_FIELD)r   usernamer   r   r   get_by_natural_key,   s    z"BaseUserManager.get_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 d Z d Z	 g  Z
 Gd d	   d	  Z d
 d   Z   f d d   Z d d   Z   f 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!   Z d" d#   Z d$ d%   Z   S)&AbstractBaseUserpassword
max_length   z
last loginZblankTnullc               @   s   e  Z d  Z d Z d S)zAbstractBaseUser.MetaTN)r$   r%   r&   Zabstractr   r   r   r   Meta9   s   r-   c             C   s   t  |  |  j  S)z-Return the identifying username for this User)getattrr!   )r   r   r   r   get_username<   s    zAbstractBaseUser.get_usernamec                s&   t  t |   j | |   d  |  _ d  S)N)superr(   __init__	_password)r   argskwargs)	__class__r   r   r1   @   s    zAbstractBaseUser.__init__c             C   s
   |  j    S)N)r/   )r   r   r   r   __str__F   s    zAbstractBaseUser.__str__c                sK   t  t |   j | |   |  j d  k	 rG t j |  j |   d  |  _ n  d  S)N)r0   r(   saver2   r   Zpassword_changed)r   r3   r4   )r5   r   r   r7   I   s    zAbstractBaseUser.savec             C   s   |  j    f S)N)r/   )r   r   r   r   natural_keyO   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   )r   r   r   r   is_anonymousR   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   )r   r   r   r   is_authenticatedY   s    z!AbstractBaseUser.is_authenticatedc             C   s   t  |  |  _ | |  _ d  S)N)r   r)   r2   )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-     j  |   d    _   j d d g  d  S)NZupdate_fieldsr)   )r<   r2   r7   )r;   )r   r   r   setteri   s    	z/AbstractBaseUser.check_password.<locals>.setter)r   r)   )r   r;   r=   r   )r   r   r   d   s    zAbstractBaseUser.check_passwordc             C   s   t  d   |  _ d  S)N)r   r)   )r   r   r   r   set_unusable_passwordp   s    z&AbstractBaseUser.set_unusable_passwordc             C   s   t  |  j  S)N)r   r)   )r   r   r   r   has_usable_passwordt   s    z$AbstractBaseUser.has_usable_passwordc             C   s   t  d   d  S)NzDsubclasses of AbstractBaseUser must provide a get_full_name() method)NotImplementedError)r   r   r   r   get_full_namew   s    zAbstractBaseUser.get_full_namec             C   s   t  d   d  S)NzFsubclasses of AbstractBaseUser must provide a get_short_name() method.)r@   )r   r   r   r   get_short_namez   s    zAbstractBaseUser.get_short_namec             C   s   d } t  | |  j  j   S)z7
        Return an HMAC of the password field.
        zAdjango.contrib.auth.models.AbstractBaseUser.get_session_auth_hash)r	   r)   	hexdigest)r   Zkey_saltr   r   r   get_session_auth_hash}   s    z&AbstractBaseUser.get_session_auth_hash)r$   r%   r&   r   Z	CharField_r)   ZDateTimeFieldZ
last_loginZ	is_activeZREQUIRED_FIELDSr-   r/   r1   r6   r7   r8   r9   r:   r<   r   r>   r?   rA   rB   rD   r   r   )r5   r   r(   0   s&   !r(   N)__doc__
__future__r   Zdjango.contrib.authr   Zdjango.contrib.auth.hashersr   r   r   Z	django.dbr   Zdjango.utils.cryptor   r	   Zdjango.utils.encodingr
   Zdjango.utils.translationr   rE   Managerr   ZModelr(   r   r   r   r   <module>   s   