
    	Ih	                         d dl mZ d dlmZmZ d dlmZmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ  G d d	e      Z G d
 de      Z eee	j$                        dd       Zy)    )models)AbstractBaseUserBaseUserManager)datedatetime	timedelta)settings)	post_save)receiver)Tokenc                       e Zd ZddZd Zy)MyAccountManagerNc                     |st        d      |st        d      | j                  | j                  |      |      }|j                  |       |j	                  | j
                         |S )Nz Users must have an email addresszUsers must have a username)emailusernameusing)
ValueErrormodelnormalize_emailset_passwordsave_dbselfr   r   passwordusers        #/var/www/html/api/account/models.pycreate_userzMyAccountManager.create_user   sk    		6	77		0	11				e	$ 
 
$
 H))$(()	+    c                     | j                  | j                  |      ||      }d|_        d|_        d|_        |j                  | j                         |S )N)r   r   r   Tr   )r   r   is_adminis_staffis_superuserr   r   r   s        r   create_superuserz!MyAccountManager.create_superuser   sZ    						e	$ 
 
$
 $-$-$))$(()	+r    N)__name__
__module____qualname__r   r%    r    r   r   r   
   s    
r    r   c                      e Zd Z ej                  dddddi      Z ej                  dd	      Z ej                  d
d      Z	 ej                  dd      Z
 ej                  dd      Z ej                         Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  dd      ZdZdgZ e       Zd ZddZd Z G d d      Zy)Accountr   <   Tuniquez$User with this email already exists.)verbose_name
max_lengthr.   error_messages   F)r0   r.   zdate joined)r/   auto_now_addz
last login)r/   auto_nowzlast logout)r/   null)defaultd   normal)r0   r6   r   c                     | j                   S r&   )r   )r   s    r   __str__zAccount.__str__:   s    	r    Nc                     | j                   S r&   )r"   )r   permobjs      r   has_permzAccount.has_perm>   s    	r    c                      y)NTr*   )r   	app_labels     r   has_module_permszAccount.has_module_permsB   s    	r    c                       e Zd ZdZy)Account.MetaaccountN)r'   r(   r)   db_tabler*   r    r   MetarC   E   s    Xr    rF   r&   )r'   r(   r)   r   
EmailFieldr   	CharFieldr   DateTimeFielddate_joined
last_loginlast_logoutlast_home_visitBooleanFieldr"   	is_activer#   r$   account_statusUSERNAME_FIELDREQUIRED_FIELDSr   objectsr:   r>   rA   rF   r*   r    r   r,   r,   &   s   fWD$&La  !  Bu=&&&&MPTU%%%<$O&&&&MtL)V))+"v""51###D1"v""51%&%%e4$F$$#J< r    r,   )senderNc                 J    |r!t         j                  j                  |       y y )N)r   )r   rS   create)rT   instancecreatedkwargss       r   create_auth_tokenrZ   I   s    (+ r    )NF)	django.dbr   django.contrib.auth.modelsr   r   r   r   r   django.confr	   django.db.models.signalsr
   django.dispatchr   rest_framework.authtoken.modelsr   r   r,   AUTH_USER_MODELrZ   r*   r    r   <module>rb      sX     H . .   . $ 1 8   F 
)H445, 6,r    