Example #1
0
class Account(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email
Example #2
0
class CustomUser(AbstractUser):
    def __str__(self):
        return f'{self.email}'

    class Meta:
        db_table = 'account_custom_user'
        verbose_name = _('User')
        verbose_name_plural = _('Users')

    username = None  # this is to remove username from model
    email = models.EmailField(verbose_name=_('E-mail'), unique=True)

    REQUIRED_FIELDS = []
    USERNAME_FIELD = 'email'

    objects = CustomUserManager()
Example #3
0
class MyUser(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField(_("First name"), max_length=50)
    last_name = models.CharField(_("Last name"), max_length=50)
    email = models.EmailField(_('email address'), unique=True)
    username = models.CharField(_("Username"), max_length=100)
    bio = models.TextField(_("User bio"), blank=True, null=True)
    profile_img = models.ImageField(_("Profile Image"),
                                    upload_to='profile-pictures/',
                                    blank=True)
    date_joined = models.DateTimeField(default=timezone.now)

    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()
Example #4
0
class User(AbstractUser):
    username = None
    email = models.EmailField(unique=True,
                              blank=False,
                              error_messages={
                                  'unique':
                                  "A user with that email already exists.",
                              })
    role = models.CharField(choices=ROLE, max_length=10)
    gender = models.CharField(choices=ITEM_TYPE, max_length=1)

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

    def __str__(self):
        return self.email

    def get_full_name(self):
        return self.first_name + ' ' + self.last_name

    objects = CustomUserManager()
Example #5
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('email address'), unique=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    date_joined = models.DateTimeField(_('date joined'), auto_now_add=True)
    is_active = models.BooleanField(_('active'), default=True)
    is_staff = models.BooleanField(_('is_staff'), default=False)
    role = models.SmallIntegerField(choices=USER_ROLES,
                                    default=USER_ROLE_EMPLOYEE)

    objects = CustomUserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def __str__(self):
        return self.email
Example #6
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('Email'), unique=True)
    phone = models.CharField(_('Phone'), unique=True, max_length=50)
    name = models.CharField(max_length=255)
    surname = models.CharField(max_length=255)
    date_joined = models.DateTimeField(default=timezone.now)
    balance = models.FloatField(default=0)
    is_active = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False)

    USERNAME_FIELD = 'phone'
    REQUIRED_FIELDS = ['email', 'name', 'surname']

    objects = CustomUserManager()

    class Meta:
        verbose_name = _("User")
        verbose_name_plural = _("Users")

    def __str__(self):
        return self.email
Example #7
0
class User(AbstractUser):
    """
    Custom user model
    """
    username = None
    email = models.EmailField(_('correo'),
                              unique=True,
                              error_messages={'unique': EMAIL_ALREADY_EXIST})
    first_name = models.CharField(_('nombres'), max_length=20, blank=True)
    last_name = models.CharField(_('apellidos'), max_length=20, blank=True)
    terms_and_conditions = models.BooleanField(_("Terms and Conditions"),
                                               default=False)
    delete_account_date = models.DateTimeField(
        _('fecha en que se eliminó la cuenta'), null=True, blank=True)
    favorites = models.ManyToManyField(Law,
                                       blank=True,
                                       verbose_name=_('favoritos'))
    profile_picture = models.ImageField(_('foto de perfil'),
                                        null=True,
                                        blank=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email

    @property
    def is_deleted(self) -> bool:
        """
        Get is account is deleted
        :return: boolean
        """
        return self.delete_account_date is not None

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
Example #8
0
class CustomUser(AbstractUser):
    MANAGER = 'MAN'
    ANALYST = 'AN'
    DEVELOPER = 'DEV'
    TESTER = 'TEST'
    ROLE_CHOICES = (
        (MANAGER, 'Manager'),
        (ANALYST, 'Analyst'),
        (DEVELOPER, 'Developer'),
        (TESTER, 'Tester'),
    )
    username = models.CharField(max_length=30,
                                verbose_name='Login',
                                unique=True)
    role = models.CharField(
        max_length=4,
        choices=ROLE_CHOICES,
    )
    room = models.ForeignKey('Room',
                             on_delete=models.SET_NULL,
                             related_name='users',
                             related_query_name='users',
                             null=True)

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.username

    def set_position(self, pos):
        self.role = pos

    def is_manager(self):
        return self.role == self.MANAGER
Example #9
0
class User(AbstractUser):
    username = None
    email = models.EmailField(unique=True,
                              blank=False,
                              error_messages={
                                  'unique':
                                  "A user with that email already exists.",
                              })
    role = models.CharField(choices=ROLE, max_length=10)
    gender = models.CharField(choices=JOB_TYPE, max_length=1)
    isActive = models.CharField(choices=active, max_length=5, default="yes")
    operate = models.CharField(choices=active, max_length=5, default="yes")
    civil = models.CharField(choices=civil_status,
                             max_length=30,
                             default="Single")

    telephone = models.CharField(max_length=15, blank=True, null=True)
    date_of_birth = models.DateField(blank=True, null=True)
    address = models.CharField(max_length=1024, blank=True, null=True)

    zip_code = models.CharField(max_length=12, blank=True, null=True)
    city = models.CharField(max_length=1024, blank=True, null=True)
    image = models.ImageField(null=True, upload_to='media', blank=True)
    is_employee = models.BooleanField(default=False)
    is_employer = models.BooleanField(default=False)

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

    def __str__(self):
        return self.email

    def get_full_name(self):
        return self.first_name + ' ' + self.last_name

    objects = CustomUserManager()
Example #10
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_("E-Mail"), max_length=254, unique=True)
    email_verified = models.BooleanField(_("E-Mail bestätigt"), default=False)
    # UUID field for identification in e.g. BBB-Service (also possibly shadow-accounts for LIMITED!!! access)
    uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(verbose_name=_("Beitritt"),
                                       auto_now_add=True)

    state = models.ForeignKey(State,
                              on_delete=models.PROTECT,
                              verbose_name=_("Bundesland"))
    first_name = models.CharField(_("Vorname"), max_length=50, blank=False)
    last_name = models.CharField(_("Nachname"), max_length=50, blank=True)

    # gender-specific
    MALE = 'MA'
    FEMALE = 'FE'
    DIVERSE = 'DI'
    GENDER_CHOICES = [(MALE, 'männlich'), (FEMALE, 'weiblich'),
                      (DIVERSE, 'divers')]

    gender = models.CharField(_("Geschlecht"),
                              max_length=2,
                              choices=GENDER_CHOICES)

    # Define Django properties
    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'state']
    objects = CustomUserManager()

    class Meta:
        verbose_name = _("Nutzer")
        verbose_name_plural = _("Nutzer")

    __email = None

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__email = self.email

    def send_verification_email(self):
        if not self.email_verified:
            token = VerificationToken.objects.get_or_create(user=self)[0]
            subject, from_email, to = "E-Mail-Bestätigung für naklar.io", "*****@*****.**", self.email
            d = {
                'user':
                self,
                'verification_url':
                settings.HOST + "/account/verify?token=" + str(token.token)
            }
            if EmailTemplate.objects.filter(name='verification_mail').exists():
                mail.send(to,
                          from_email,
                          template='verification_mail',
                          context=d)
            else:
                text_content = EMAIL_VERIFICATION_PLAINTEXT.render(d)
                html_content = EMAIL_VERIFICATION_HTMLY.render(d)
                mail.send(to,
                          from_email,
                          subject=subject,
                          message=text_content,
                          html_message=html_content)

    def check_email_verification(self, check_token):
        if str(self.verificationtoken.token) == str(check_token):
            self.email_verified = True
            self.verificationtoken.delete()
            self.save()
            return True
        else:
            return False

    def send_reset_mail(self):
        PasswordResetToken.objects.filter(user=self).delete()
        token = PasswordResetToken(user=self)
        token.save()
        subject, from_email, to = "Passwort zurücksetzen auf naklar.io", "*****@*****.**", self.email
        d = {
            'user':
            self,
            'reset_url':
            settings.HOST + "/account/password-reset/{}".format(token.token)
        }
        if EmailTemplate.objects.filter(name='password_reset').exists():
            mail.send(to, from_email, template='password_reset', context=d)
        else:
            text_content = PASSWORD_RESET_PLAINTEXT.render(d)
            html_content = PASSWORD_RESET_HTMLY.render(d)
            mail.send(to,
                      from_email,
                      subject=subject,
                      message=text_content,
                      html_message=html_content)

    def is_tutor(self):
        return hasattr(self, 'tutordata')

    def is_student(self):
        return hasattr(self, 'studentdata')

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.__email.lower() != self.email.lower():
            self.email_verified = False
            self.send_verification_email()

        return super(CustomUser, self).save(force_insert=force_insert,
                                            force_update=force_update,
                                            using=using,
                                            update_fields=update_fields)

    is_tutor.boolean = True
    is_tutor.admin_order_field = 'tutordata'
    is_student.boolean = True
    is_student.admin_order_field = 'studentdata'

    def __str__(self):
        return self.email