
    k"g|@                        d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ ddlmZ d Z G d dej:                        Z G d dej>                        Z  G d dej:                        Z! G d dej>                        Z" G d de      Z#d Z$d Z%d Z& G d dej>                        Z' G d d ee'      Z( G d! d"e(      Z) G d# d$      Z*y%)&    )Iterable)apps)auth)AbstractBaseUserBaseUserManager)make_password)ContentType)PermissionDenied)	send_mail)models)EmptyManager)timezone)gettext_lazy   )UnicodeUsernameValidatorc                 \    t        j                         |_        |j                  dg       y)zZ
    A signal receiver which updates the last_login date for
    the user logging in.
    
last_login)update_fieldsN)r   nowr   save)senderuserkwargss      S/var/www/html/djangosite/lib/python3.12/site-packages/django/contrib/auth/models.pyupdate_last_loginr      s!    
 llnDOII\NI+    c                       e Zd ZdZd Zy)PermissionManagerTc                     | j                  |t        j                  j                  | j                        j                  ||            S )N)codenamecontent_type)getr	   objects
db_managerdbget_by_natural_key)selfr    	app_labelmodels       r   r&   z$PermissionManager.get_by_natural_key   sC    xx$,,77@SS5  
 	
r   N)__name__
__module____qualname__use_in_migrationsr&    r   r   r   r      s    
r   r   c                       e Zd ZdZ ej
                   ed      d      Z ej                  e	ej                   ed            Z ej
                   ed      d      Z e       Z G d	 d
      Zd Zd Zdge_        y)
PermissionaC  
    The permissions system provides a way to assign permissions to specific
    users and groups of users.

    The permission system is used by the Django admin site, but may also be
    useful in your own code. The Django admin site uses permissions as follows:

        - The "add" permission limits the user's ability to view the "add" form
          and add an object.
        - The "change" permission limits a user's ability to view the change
          list, view the "change" form and change an object.
        - The "delete" permission limits the ability to delete an object.
        - The "view" permission limits the ability to view an object.

    Permissions are set globally per type of object, not per specific object
    instance. It is possible to say "Mary may change news stories," but it's
    not currently possible to say "Mary may change news stories, but only the
    ones she created herself" or "Mary may only change news stories that have a
    certain status or publication date."

    The permissions listed above are automatically created for each model.
    name   )
max_lengthzcontent type)verbose_namer    d   c                   >    e Zd Z ed      Z ed      ZddggZg dZy)Permission.Meta
permissionpermissionsr!   r    )content_type__app_labelcontent_type__modelr    N)r*   r+   r,   _r4   verbose_name_pluralunique_togetherorderingr.   r   r   Metar7   I   s(    .*J78Qr   r@   c                 8    | j                   d| j                  S )Nz | )r!   r1   r'   s    r   __str__zPermission.__str__O   s     --tyy99r   c                 R    | j                   f| j                  j                         z   S N)r    r!   natural_keyrB   s    r   rF   zPermission.natural_keyR   s#    $"3"3"?"?"AAAr   zcontenttypes.contenttypeN)r*   r+   r,   __doc__r   	CharFieldr<   r1   
ForeignKeyr	   CASCADEr!   r    r   r#   r@   rC   rF   dependenciesr.   r   r   r0   r0   '   s    . 6AfI#6D$6$$~&L
  v*#>H!GR R:B !;;Kr   r0   c                       e Zd ZdZdZd Zy)GroupManagerz1
    The manager for the auth's Group model.
    Tc                 &    | j                  |      S )Nr1   )r"   )r'   r1   s     r   r&   zGroupManager.get_by_natural_key_   s    xxTx""r   N)r*   r+   r,   rG   r-   r&   r.   r   r   rM   rM   X   s     #r   rM   c                       e Zd ZdZ ej
                   ed      dd      Z ej                  e	 ed      d      Z
 e       Z G d d	      Zd
 Zd Zy)Groupa	  
    Groups are a generic way of categorizing users to apply permissions, or
    some other label, to those users. A user can belong to any number of
    groups.

    A user in a group automatically has all the permissions granted to that
    group. For example, if the group 'Site editors' has the permission
    can_edit_home_page, any user in that group will have that permission.

    Beyond permissions, groups are a convenient way to categorize users to
    apply some label, or extended functionality, to them. For example, you
    could create a group 'Special users', and you could write code that would
    do special things to those users -- such as giving them access to a
    members-only portion of your site, or sending them members-only email
    messages.
    r1      T)r3   uniquer9   )r4   blankc                   ,    e Zd Z ed      Z ed      Zy)
Group.MetagroupgroupsN)r*   r+   r,   r<   r4   r=   r.   r   r   r@   rV   ~   s    zkr   r@   c                     | j                   S rE   rO   rB   s    r   rC   zGroup.__str__   s    yyr   c                     | j                   fS rE   rO   rB   s    r   rF   zGroup.natural_key   s    		|r   N)r*   r+   r,   rG   r   rH   r<   r1   ManyToManyFieldr0   r9   rM   r#   r@   rC   rF   r.   r   r   rQ   rQ   c   s`    " 6AfI#dCD(&((}%K nG* *r   rQ   c                   0    e Zd ZdZd ZddZddZ	 ddZy)	UserManagerTc                    |st        d      | j                  |      }t        j                  | j                  j
                  j                  | j                  j
                  j                        }|j                  |      } | j                  d||d|}t        |      |_
        |j                  | j                         |S )zV
        Create and save a user with the given username, email, and password.
        zThe given username must be set)usernameemail)usingr.   )
ValueErrornormalize_emailr   	get_modelr)   _metar(   object_namenormalize_usernamer   passwordr   _db)r'   r_   r`   rh   extra_fieldsGlobalUserModelr   s          r   _create_userzUserManager._create_user   s     =>>$$U+ ..JJ&&

(8(8(D(D
 #55h?tzzI85ILI%h/			!r   Nc                 t    |j                  dd       |j                  dd        | j                  |||fi |S )Nis_staffFis_superuser)
setdefaultrl   r'   r_   r`   rh   rj   s        r   create_userzUserManager.create_user   s>    
E26 t  5(KlKKr   c                     |j                  dd       |j                  dd       |j                  d      durt        d      |j                  d      durt        d       | j                  |||fi |S )Nrn   Tro   z"Superuser must have is_staff=True.z&Superuser must have is_superuser=True.)rp   r"   rb   rl   rq   s        r   create_superuserzUserManager.create_superuser   s|    
D15J't3ABBN+47EFF t  5(KlKKr   c                 >   |8t        j                  d      }t        |      dk(  r	|d   \  }}n>t        d      t	        |t
              st        d|z        t        j                  |      }t        |d      r|j                  ||||      S | j                         S )	NT)return_tuplesr   r   zgYou have multiple authentication backends configured and therefore must provide the `backend` argument.z5backend must be a dotted import path string (got %r).	with_perm)	is_activeinclude_superusersobj)r   _get_backendslenrb   
isinstancestr	TypeErrorload_backendhasattrrw   none)r'   permrx   ry   backendrz   backendsr<   s           r   rw   zUserManager.with_perm   s     ?))=H8}!%a[
 E  GS)G'Q  ''0G7K($$##5	 %   yy{r   )NN)TTNN)r*   r+   r,   r-   rl   rr   rt   rw   r.   r   r   r]   r]      s%    &L
	L PTr   r]   c                     t               }d|z  }t        j                         D ]1  }t        ||      s|j	                   t        ||      | |             3 |S )Nzget_%s_permissions)setr   get_backendsr   updategetattr)r   rz   	from_namer9   r1   r   s         r   _user_get_permissionsr      s^    %K)+D$$& B7D!5ww5dC@AB r   c                     t        j                         D ]%  }t        |d      s	 |j                  | ||      r y' y# t        $ r Y  yw xY w)V
    A backend can raise `PermissionDenied` to short-circuit permission checking.
    has_permTF)r   r   r   r   r
   )r   r   rz   r   s       r   _user_has_permr      sa     $$& w
+	dC0 1	    		s   >	A
Ac                     t        j                         D ]$  }t        |d      s	 |j                  | |      r y& y# t        $ r Y  yw xY w)r   has_module_permsTF)r   r   r   r   r
   )r   r(   r   s      r   _user_has_module_permsr      s`     $$& w 23	''i8 9	    		s   =	A
	A
c                   $   e Zd ZdZ ej
                   ed      d ed            Z ej                  e	 ed      d ed      d	d
      Z
 ej                  e ed      d ed      d	d
      Z G d d      ZddZddZddZddZddZd Zy)PermissionsMixinzu
    Add the fields and methods necessary to support the Group and Permission
    models using the ModelBackend.
    zsuperuser statusFzPDesignates that this user has all permissions without explicitly assigning them.default	help_textrX   TzaThe groups this user belongs to. A user will get all permissions granted to each of their groups.user_setr   )r4   rT   r   related_namerelated_query_namezuser permissionsz#Specific permissions for this user.c                       e Zd ZdZy)PermissionsMixin.MetaTN)r*   r+   r,   abstractr.   r   r   r@   r     s    r   r@   Nc                     t        | |d      S )z
        Return a list of permission strings that this user has directly.
        Query all available auth backends. If an object is passed in,
        return only permissions matching this object.
        r   r   r'   rz   s     r   get_user_permissionsz%PermissionsMixin.get_user_permissions  s     %T377r   c                     t        | |d      S )z
        Return a list of permission strings that this user has through their
        groups. Query all available auth backends. If an object is passed in,
        return only permissions matching this object.
        rW   r   r   s     r   get_group_permissionsz&PermissionsMixin.get_group_permissions   s     %T388r   c                     t        | |d      S Nallr   r   s     r   get_all_permissionsz$PermissionsMixin.get_all_permissions(      $T366r   c                 N    | j                   r| j                  ryt        | ||      S )a`  
        Return True if the user has the specified permission. Query all
        available auth backends, but return immediately if any backend returns
        True. Thus, a user who has permission from a single auth backend is
        assumed to have permission in general. If an object is provided, check
        permissions for that object.
        T)rx   ro   r   r'   r   rz   s      r   r   zPermissionsMixin.has_perm+  s'     >>d// dD#..r   c                      t        |t              rt        |t              rt        d      t	         fd|D              S )z
        Return True if the user has each of the specified permissions. If
        object is passed, check if the user has all required perms for it.
        -perm_list must be an iterable of permissions.c              3   B   K   | ]  }j                  |        y wrE   r   .0r   rz   r'   s     r   	<genexpr>z-PermissionsMixin.has_perms.<locals>.<genexpr>A       B4==s+B   r}   r   r~   rb   r   r'   	perm_listrz   s   ` `r   	has_permszPermissionsMixin.has_perms:  s5    
 )X.*Y2LLMMB	BBBr   c                 L    | j                   r| j                  ryt        | |      S )z
        Return True if the user has any permissions in the given app label.
        Use similar logic as has_perm(), above.
        T)rx   ro   r   )r'   r(   s     r   r   z!PermissionsMixin.has_module_permsC  s#     >>d//%dI66r   rE   )r*   r+   r,   rG   r   BooleanFieldr<   ro   r[   rQ   rX   r0   user_permissionsr@   r   r   r   r   r   r   r.   r   r   r   r      s    
 '6&&	
)
L $V##x[/
  !
F .v--)*9:! 897/C	7r   r   c                   :    e Zd ZdZ e       Z ej                   ed      dd ed      egd ed      i      Z	 ej                   ed	      dd
      Z
 ej                   ed      dd
      Z ej                   ed      d      Z ej                   ed      d ed            Z ej                   ed      d ed            Z ej"                   ed      ej&                        Z e       ZdZdZdgZ G d d      Z fdZd Zd ZddZ xZS )AbstractUserz
    An abstract base class implementing a fully featured User model with
    admin-compliant permissions.

    Username and password are required. Other fields are optional.
    r_   rR   TzFRequired. 150 characters or fewer. Letters, digits and @/./+/-/_ only.rS   z)A user with that username already exists.)r3   rS   r   
validatorserror_messagesz
first name)r3   rT   z	last namezemail address)rT   zstaff statusFz9Designates whether the user can log into this admin site.r   activezeDesignates whether this user should be treated as active. Unselect this instead of deleting accounts.zdate joined)r   r`   c                   0    e Zd Z ed      Z ed      ZdZy)AbstractUser.Metar   usersTN)r*   r+   r,   r<   r4   r=   r   r.   r   r   r@   r   }  s    yjr   r@   c                     t         |           | j                  j                  j	                  | j
                        | _        y rE   )superclean	__class__r#   rc   r`   )r'   r   s    r   r   zAbstractUser.clean  s,    ^^++;;DJJG
r   c                 X    | j                   d| j                  }|j                         S )zT
        Return the first_name plus the last_name, with a space in between.
         )
first_name	last_namestrip)r'   	full_names     r   get_full_namezAbstractUser.get_full_name  s#      $?	  r   c                     | j                   S )z#Return the short name for the user.)r   rB   s    r   get_short_namezAbstractUser.get_short_name  s    r   c                 8    t        |||| j                  gfi | y)zSend an email to this user.N)r   r`   )r'   subjectmessage
from_emailr   s        r   
email_userzAbstractUser.email_user  s    '7JGGr   rE   ) r*   r+   r,   rG   r   username_validatorr   rH   r<   r_   r   r   
EmailFieldr`   r   rn   rx   DateTimeFieldr   r   date_joinedr]   r#   EMAIL_FIELDUSERNAME_FIELDREQUIRED_FIELDSr@   r   r   r   r   __classcell__)r   s   @r   r   r   O  sL    23v	*T
 ''aCD
H "!!!L/cNJ   ;CtLIFa0=E"v""	.OPH
 $##	(:
I '&&&q'7NKmGKNiO 
H!Hr   r   c                   :    e Zd ZdZ G d dej
                        Zy)Userz
    Users within the Django authentication system are represented by this
    model.

    Username and password are required. Other fields are optional.
    c                       e Zd ZdZy)	User.MetaAUTH_USER_MODELN)r*   r+   r,   	swappabler.   r   r   r@   r     s    %	r   r@   N)r*   r+   r,   rG   r   r@   r.   r   r   r   r     s    &|   &r   r   c                       e Zd ZdZdZdZdZdZdZ e	e
      Z e	e      Zd Zd Zd Zd Zd Zd	 Zd
 Zd Zed        Zed        ZddZddZddZddZddZd Zed        Zed        Z d Z!y)AnonymousUserN Fc                      y)Nr   r.   rB   s    r   rC   zAnonymousUser.__str__  s    r   c                 .    t        || j                        S rE   )r}   r   )r'   others     r   __eq__zAnonymousUser.__eq__  s    %00r   c                      y)Nr   r.   rB   s    r   __hash__zAnonymousUser.__hash__  s    r   c                     t        d      )NzLCannot cast AnonymousUser to int. Are you trying to use it in place of User?)r   rB   s    r   __int__zAnonymousUser.__int__  s    
 	
r   c                     t        d      Nz=Django doesn't provide a DB representation for AnonymousUser.NotImplementedErrorrB   s    r   r   zAnonymousUser.save      !K
 	
r   c                     t        d      r   r   rB   s    r   deletezAnonymousUser.delete  r   r   c                     t        d      r   r   r'   raw_passwords     r   set_passwordzAnonymousUser.set_password  r   r   c                     t        d      r   r   r   s     r   check_passwordzAnonymousUser.check_password  r   r   c                     | j                   S rE   )_groupsrB   s    r   rX   zAnonymousUser.groups  s    ||r   c                     | j                   S rE   )_user_permissionsrB   s    r   r   zAnonymousUser.user_permissions  s    %%%r   c                     t        | |d      S )Nr   r   r   s     r   r   z"AnonymousUser.get_user_permissions  s    $T377r   c                     t               S rE   )r   r   s     r   r   z#AnonymousUser.get_group_permissions  s	    ur   c                     t        | |d      S r   r   r   s     r   r   z!AnonymousUser.get_all_permissions  r   r   c                     t        | ||      S )N)rz   )r   r   s      r   r   zAnonymousUser.has_perm  s    dDc22r   c                      t        |t              rt        |t              rt        d      t	         fd|D              S )Nr   c              3   B   K   | ]  }j                  |        y wrE   r   r   s     r   r   z*AnonymousUser.has_perms.<locals>.<genexpr>  r   r   r   r   s   ` `r   r   zAnonymousUser.has_perms  s3    )X.*Y2LLMMB	BBBr   c                     t        | |      S rE   )r   )r'   modules     r   r   zAnonymousUser.has_module_perms  s    %dF33r   c                      y)NTr.   rB   s    r   is_anonymouszAnonymousUser.is_anonymous  s    r   c                      y)NFr.   rB   s    r   is_authenticatedzAnonymousUser.is_authenticated  s    r   c                     | j                   S rE   )r_   rB   s    r   get_usernamezAnonymousUser.get_username  s    }}r   rE   )"r*   r+   r,   idpkr_   rn   rx   ro   r   rQ   r   r0   r   rC   r   r   r   r   r   r   r   propertyrX   r   r   r   r   r   r   r   r	  r  r  r.   r   r   r   r     s    	B	BHHIL5!G$Z01








   & &873C
4    r   r   N)+collections.abcr   django.appsr   django.contribr   django.contrib.auth.base_userr   r   django.contrib.auth.hashersr   "django.contrib.contenttypes.modelsr	   django.core.exceptionsr
   django.core.mailr   	django.dbr   django.db.models.managerr   django.utilsr   django.utils.translationr   r<   r   r   r   Managerr   Modelr0   rM   rQ   r]   r   r   r   r   r   r   r   r.   r   r   <module>r     s    $   K 5 : 3 &  1 ! 6 0,	
 	
.< .<b#6>> ##FLL #L?/ ?FY7v|| Y7xDH#%5 DHN	&< 	&R Rr   