models.py¶
This module contains the User model and other models for storing login attempts, a list of old hashed passwords, password change request and temporarily storages of the (hashed) login sms code.
- An user is coupled to one of the 4 different possible roles in Remote Care:
- Patient
- Healthprofessional
- Secretary
- Manager
Via the polymorphicmodel: apps.healthperson.models.HealthPerson as can
be seen in the next model relationship diagram:
All personal user data is stored encrypted and, if searchable, also hashed. This key for encryption/decryption is the encryption_key of the user which is encrypted/decrypted with the MASTER_KEY in the settings file. The hashes are in HMAC format. The HMAC secrets are stored in the settings file.
Users are hospital ‘bound’ meaning that an healthprofessional/secretary can only find patients within the same hospital during searching.
Class definitions:
-
class
apps.account.models.UserManager[source]¶ Bases:
django.contrib.auth.base_user.BaseUserManagerCustom user manager which allows adding an user via the manage.py command using email as unique key and filling in other required information
-
class
apps.account.models.EncryptionKey(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelStores all encryption keys of the users.
Encrypts/decrypts them with the MASTER_KEY setting.
Parameters: - id (AutoField) –
- key (
EncryptedCharField) –
-
class
apps.account.models.User(*args, **kwargs)[source]¶ Bases:
django.contrib.auth.base_user.AbstractBaseUser,django.contrib.auth.models.PermissionsMixin,core.models.AuditBaseModelCustom user model which saves basic information about the user. All private information is encrypted.
Private information is stored encrypted in the database via encrypted model fields. See the
core.models.EncryptBaseFieldfor more information on encryption.Private information that should also be searchable is represented by both an encrypted field and an HMAC field. See the
core.models.EncryptLookupBaseFieldfor more information on encryption and HMAC lookup.Parameters: - id (AutoField) –
- password (CharField) –
- last_login (DateTimeField) –
- is_superuser (BooleanField) –
- personal_encryption_key_id (OneToOneField to
EncryptionKey) – - hmac_first_name (
HMACField) – - first_name (
EncryptedHMACLookupCharField) – - hmac_last_name (
HMACField) – - last_name (
EncryptedHMACLookupCharField) – - hmac_email (
HMACField) – - email (
EncryptedHMACLookupEmailField) – - title (CharField) – choices=[mr, ms, dr, prof]
- initials (CharField) –
- prefix (CharField) –
- mobile_number (
EncryptedCharField) – - gender (CharField) – choices=[male, female]
- hospital_id (ForeignKey to
Hospital) – - hmac_local_hospital_number (
HMACField) – - local_hospital_number (
EncryptedHMACLookupCharField) – - hmac_BSN (
HMACField) – - BSN (
EncryptedHMACLookupCharField) – - date_of_birth (
DateField) – - healthperson_id (OneToOneField to
HealthPerson) – - is_staff (BooleanField) –
- is_active (BooleanField) –
- date_joined (DateTimeField) –
- account_blocked (
YesNoChoiceField) – - deleted_on (DateField) –
-
new_questionnaire_request¶ Returns true if the patient has no questionnaire requests
-
new_message_count¶ Returns the amount of unread messages
-
full_name¶ Returns the full_name of an user which is: first_name + prefix + last_name
-
professional_name¶ Returns the full_name of an user which is: initials + prefix + last_name
-
is_deleted¶ Returns True if the user has been set for deletion.
-
audit_encryption_key_id¶ Get the EncryptionKey id so it can be coupled to the log item in the audit.
- Returns:
- The id of the EncryptionKey that is used to encrypt the model instance.
-
encryption_key¶ Get the encryption key of the user.
- Returns:
- The encryption key of the user instance.
-
class
apps.account.models.LoginAttempt(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelStores all login attempts for administration purposes. Login attempts with extra info and an hash of the username = email address
Parameters: - id (AutoField) –
- succesfull (
YesNoChoiceField) – - ipaddress (CharField) –
- useragent (TextField) –
- extra_info (TextField) –
- session_id (TextField) –
- date (DateTimeField) –
- username_hash (TextField) –
-
class
apps.account.models.LoginSMSCode(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelTemporarily stores the hmac_sms_code used during login
Parameters: - id (AutoField) –
- user_id (ForeignKey to
User) – - hmac_sms_code (CharField) –
-
class
apps.account.models.OldPassword(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelStores previous passwords and the current password. Can both be used to validate that the password is different from the # last passwords and check if the password is expired.
Parameters:
-
class
apps.account.models.PasswordChangeRequest(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelTemporarly stores the sms_code and key for resetting the password. Email and sms HMAC thus when set only can check using HMAC secret. The attempt_nr field is used to limit the total amount of attempts possible.
Parameters: