
    2fhn                     |    d dl mZ d dlmZ d dlmZ  G d dej                        Z G d dej                        Zy)	    )User)models)timezonec                   H   e Zd Z ej                  eej                  d      Z ej                  eej                  dddd      Z
 ej                  dd      Z ej                  d	d
      Z ej                  dddd      Z ej                  dddd      Z ej                  dddd      Z ej&                  dddd      Z ej&                  dddd      Z ej                  dd      Z ej.                  d      Z ej.                  d      Zd Z G d d      Zy)UserProfileprofile	on_deleterelated_nameTcreated_userszUser who created this account)r
   nullblankr   	help_textz$Super admin has full database accessdefaultr   r   z$Number of properties managed by user   zUser's phone number
max_lengthr   r   r      zCompany named   zJob title/positioni  zProfile image URLzCompany logo URLFz,Whether two-factor authentication is enabledauto_now_addauto_nowc                 X    | j                   rdnd}| j                  j                   d| S )NzSuper AdminAdmin - )super_adminuserusername)selfroles     /backend/users/models.py__str__zUserProfile.__str__?   s-     $ 0 0}g))$$%S//    c                       e Zd ZdZy)UserProfile.Metauser_profilesN)__name__
__module____qualname__db_table r%   r#   Metar'   C   s    "r%   r.   N)r)   r*   r+   r   OneToOneFieldr   CASCADEr   
ForeignKeySET_NULL
created_byBooleanFieldr   PositiveIntegerFieldproperty_count	CharFieldphone_numbercompany	job_titleURLField	image_urlcompany_logo_urltwo_factor_enabledDateTimeField
created_at
updated_atr$   r.   r-   r%   r#   r   r      se   6YWD"""//$1J &&%%8K 1V008N $6##'	L f 	G !  &	I  %	I 'v$	 -,,@ &%%48J%%%t4J0# #r%   r   c                   F   e Zd Z ej                  eej                  d      Z ej                  ddd      Z	 ej                  d      Z ej                  d	      Z ej                  d
ddd      Z ej                  dddd      Z ej                  dddd      Z ej                  dddd      Z ej$                  dd      Z ej(                  d      Z ej(                  d      Z ej(                  dd      Z G d d      Zd Zed        Zed        Zy)LoginSessionlogin_sessionsr	   (   TzDjango session key)r   uniquer   zIP address of login)r   zBrowser/device user agent2   z#Device type (Mobile, Desktop, etc.)r   r   zBrowser namezOperating system   zApproximate locationzWhether session is still activer   r   r   )r   r   c                       e Zd ZdZdgZy)LoginSession.MetarD   z-login_timeN)r)   r*   r+   r,   orderingr-   r%   r#   r.   rJ   T   s    #!?r%   r.   c                 f    | j                   j                   d| j                   d| j                   S )Nr   )r   r    device_type
login_timer!   s    r#   r$   zLoginSession.__str__X   s0    ))$$%S)9)9(:#doo=NOOr%   c                 N    | j                   r| j                   | j                  z
  S y)zCalculate session durationN)logout_timerN   rO   s    r#   session_durationzLoginSession.session_duration[   s%     ##doo55r%   c                     | j                   r| j                  ryt        j                         t        j                  d      z
  }| j
                  |kD  S )z&Check if this is an active JWT sessionFi  )hours)	is_activerQ   r   now	timedeltarN   )r!   cutoffs     r#   is_current_sessionzLoginSession.is_current_sessionb   sB    
 ~~!1!1 ("4"45"AA''r%   N)r)   r*   r+   r   r1   r   r0   r   r7   session_keyGenericIPAddressField
ip_address	TextField
user_agentrM   browseroperating_systemlocationr4   rU   r?   rN   last_activityrQ   r.   r$   propertyrR   rY   r-   r%   r#   rC   rC   F   sD   6TV^^JZ[D"&""bI]^K---8MNJ!!!,GHJ"&""b4SxyKf#TP^_G'v''3dYklv3dQghH###D<]^I%%%48J(F(($7M&&&&D=K# #P   
( 
(r%   rC   N)	django.contrib.auth.modelsr   	django.dbr   django.utilsr   Modelr   rC   r-   r%   r#   <module>rh      s/    +  !?#&,, ?#B'(6<< '(r%   