o 3a@sdZddlZddlmZddlmZddlmZmZm Z ddl m Z ddl m Z mZddlmZGd d d e jZGd d d e jZdS) zg This module allows importing AbstractBaseUser even when django.contrib.auth is not in INSTALLED_APPS. N)settings)password_validation)check_passwordis_password_usable make_password)models)get_random_string salted_hmac) gettext_lazyc@s.eZdZeddZ  d ddZddZd S) BaseUserManagercCsJ|pd}z |dd\}}Wn tyY|Sw|d|}|S)zS Normalize the email address by lowercasing the domain part of it. @)striprsplit ValueErrorlower)clsemail email_name domain_partr?/usr/lib/python3/dist-packages/django/contrib/auth/base_user.pynormalize_emails zBaseUserManager.normalize_email 7abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789cCs 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)selflength allowed_charsrrrmake_random_password!s z$BaseUserManager.make_random_passwordcCs|jdi|jj|iS)Nr)getmodelUSERNAME_FIELD)rusernamerrrget_by_natural_key,sz"BaseUserManager.get_by_natural_keyN)rr)__name__ __module__ __qualname__ classmethodrrr$rrrrr s   r cseZdZejedddZejeddddZdZ gZ dZ Gdd d Z d d Z fd d ZddZddZddZeddZeddZddZddZddZddZd d!Zd"d#Zed$d%Zed&d'ZZS)(AbstractBaseUserpassword) max_lengthz last loginT)blanknullNc@seZdZdZdS)zAbstractBaseUser.MetaTN)r%r&r'abstractrrrrMeta<sr0cCs|SN get_usernamerrrr__str__?szAbstractBaseUser.__str__cs8tj|i||jdurt|j|d|_dSdSr1)supersave _passwordrpassword_changed)rargskwargs __class__rrr7Bs   zAbstractBaseUser.savecCs t||jS)z"Return the username for this User.)getattrr"r4rrrr3Hs zAbstractBaseUser.get_usernamecCst||j||dSr1)setattrr"normalize_usernamer3r4rrrcleanLszAbstractBaseUser.cleancCs |fSr1r2r4rrr natural_keyOs zAbstractBaseUser.natural_keycCdS)zj Always return False. This is a way of comparing User objects to anonymous users. Frr4rrr is_anonymousRzAbstractBaseUser.is_anonymouscCrC)zt Always return True. This is a way to tell if the user has been authenticated in templates. Trr4rrris_authenticatedZrEz!AbstractBaseUser.is_authenticatedcCst||_||_dSr1)rr*r8)r raw_passwordrrr set_passwordbs  zAbstractBaseUser.set_passwordcsfdd}t|j|S)z~ Return a boolean of whether the raw_password was correct. Handles hashing formats behind the scenes. cs"|d_jdgddS)Nr*) update_fields)rHr8r7)rGr4rrsetterks z/AbstractBaseUser.check_password..setter)rr*)rrGrJrr4rrfs zAbstractBaseUser.check_passwordcCstd|_dSr1)rr*r4rrrset_unusable_passwordrsz&AbstractBaseUser.set_unusable_passwordcCs t|jS)zX Return False if set_unusable_password() has been called for this user. )rr*r4rrrhas_usable_passwordvs z$AbstractBaseUser.has_usable_passwordcCsd}t||jddS)NAdjango.contrib.auth.models.AbstractBaseUser.get_session_auth_hashsha1 algorithm)r r* hexdigestrkey_saltrrr_legacy_get_session_auth_hash|sz.AbstractBaseUser._legacy_get_session_auth_hashcCsd}t||jtjdS)z7 Return an HMAC of the password field. rMrO)r r*rDEFAULT_HASHING_ALGORITHMrQrRrrrget_session_auth_hashsz&AbstractBaseUser.get_session_auth_hashcCsz|jWStyYdSw)Nr) EMAIL_FIELDAttributeError)rrrrget_email_field_names  z%AbstractBaseUser.get_email_field_namecCst|tr td|S|S)NNFKC) isinstancestr unicodedata normalize)rr#rrrr@sz#AbstractBaseUser.normalize_username)r%r&r'r CharField_r* DateTimeField last_login is_activeREQUIRED_FIELDSr8r0r5r7r3rArBpropertyrDrFrHrrKrLrTrVr(rYr@ __classcell__rrr<rr)0s4     r))__doc__r] django.confrdjango.contrib.authrdjango.contrib.auth.hashersrrr django.dbrdjango.utils.cryptorr django.utils.translationr r`Managerr Modelr)rrrrs