You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
2.7 KiB

  1. import uuid
  2. from django.db import models
  3. from django.contrib.auth.models import (
  4. BaseUserManager, AbstractBaseUser
  5. )
  6. class LesspassUserManager(BaseUserManager):
  7. def create_user(self, email, password=None):
  8. if not email:
  9. raise ValueError('Users must have an email address')
  10. user = self.model(
  11. email=self.normalize_email(email),
  12. )
  13. user.set_password(password)
  14. user.save(using=self._db)
  15. return user
  16. def create_superuser(self, email, password):
  17. user = self.create_user(email, password=password, )
  18. user.is_admin = True
  19. user.save(using=self._db)
  20. return user
  21. class LessPassUser(AbstractBaseUser):
  22. email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
  23. is_active = models.BooleanField(default=True)
  24. is_admin = models.BooleanField(default=False)
  25. objects = LesspassUserManager()
  26. USERNAME_FIELD = 'email'
  27. def get_full_name(self):
  28. return self.email
  29. def get_short_name(self):
  30. return self.email
  31. def __str__(self):
  32. return self.email
  33. def has_perm(self, perm, obj=None):
  34. return True
  35. def has_module_perms(self, app_label):
  36. return True
  37. @property
  38. def is_staff(self):
  39. return self.is_admin
  40. class Meta:
  41. verbose_name_plural = "Users"
  42. class DateMixin(models.Model):
  43. created = models.DateTimeField(auto_now_add=True, verbose_name='created')
  44. modified = models.DateTimeField(auto_now=True, verbose_name='modified')
  45. class Meta:
  46. abstract = True
  47. class PasswordInfo(models.Model):
  48. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  49. counter = models.IntegerField(default=1)
  50. settings = models.TextField()
  51. length = models.IntegerField(default=12)
  52. class Meta:
  53. verbose_name_plural = "Password info"
  54. def __str__(self):
  55. return str(self.id)
  56. class Entry(DateMixin):
  57. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  58. user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='entries')
  59. login = models.CharField(max_length=255, default='')
  60. site = models.CharField(max_length=255, default='')
  61. password = models.ForeignKey(PasswordInfo)
  62. title = models.CharField(max_length=255, null=True, blank=True)
  63. username = models.CharField(max_length=255, null=True, blank=True)
  64. email = models.EmailField(null=True, blank=True)
  65. description = models.TextField(null=True, blank=True)
  66. url = models.URLField(null=True, blank=True)
  67. class Meta:
  68. verbose_name_plural = "Entries"
  69. def __str__(self):
  70. return str(self.id)