Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

121 строка
3.4 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_superuser(self):
  39. return self.is_admin
  40. @property
  41. def is_staff(self):
  42. return self.is_admin
  43. class Meta:
  44. verbose_name_plural = "Users"
  45. class DateMixin(models.Model):
  46. created = models.DateTimeField(auto_now_add=True, verbose_name='created')
  47. modified = models.DateTimeField(auto_now=True, verbose_name='modified')
  48. class Meta:
  49. abstract = True
  50. class Password(DateMixin):
  51. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  52. user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='passwords')
  53. login = models.CharField(max_length=255, null=True, blank=True)
  54. site = models.CharField(max_length=255, null=True, blank=True)
  55. lowercase = models.BooleanField(default=True)
  56. uppercase = models.BooleanField(default=True)
  57. symbols = models.BooleanField(default=True)
  58. numbers = models.BooleanField(default=True)
  59. length = models.IntegerField(default=12)
  60. counter = models.IntegerField(default=1)
  61. def __str__(self):
  62. return str(self.id)
  63. class PasswordInfo(models.Model):
  64. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  65. counter = models.IntegerField(default=1)
  66. settings = models.TextField()
  67. length = models.IntegerField(default=12)
  68. class Meta:
  69. verbose_name_plural = "Password info"
  70. def __str__(self):
  71. return str(self.id)
  72. class Entry(DateMixin):
  73. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  74. user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='entries')
  75. login = models.CharField(max_length=255, default='')
  76. site = models.CharField(max_length=255, default='')
  77. password = models.ForeignKey(PasswordInfo)
  78. title = models.CharField(max_length=255, null=True, blank=True)
  79. username = models.CharField(max_length=255, null=True, blank=True)
  80. email = models.EmailField(null=True, blank=True)
  81. description = models.TextField(null=True, blank=True)
  82. url = models.URLField(null=True, blank=True)
  83. class Meta:
  84. verbose_name_plural = "Entries"
  85. def __str__(self):
  86. return str(self.id)