Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

91 Zeilen
2.3 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=16)
  60. counter = models.IntegerField(default=1)
  61. version = models.IntegerField(default=2)
  62. def __str__(self):
  63. return str(self.id)