Skip to content

Instantly share code, notes, and snippets.

@tmirza-dinCloud
Created June 13, 2020 16:12
Show Gist options
  • Save tmirza-dinCloud/51b590e1c4694747e4a5ac25f7649bc7 to your computer and use it in GitHub Desktop.
Save tmirza-dinCloud/51b590e1c4694747e4a5ac25f7649bc7 to your computer and use it in GitHub Desktop.
from __future__ import unicode_literals
from django.db import models
from django.core.mail import send_mail
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.base_user import BaseUserManager
class UserManager(BaseUserManager):
use_in_migrations = True
def create_superuser(self, email, password, **extra_fields):
if password is None:
raise TypeError("provide password please")
myuser = self.model(email=email, password=password)
myuser.set_password(password)
myuser.is_admin = True
myuser.is_staff = True
myuser.is_superuser = True
myuser.save()
class User(AbstractBaseUser):
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False)
is_staff = models.BooleanField(default=True)
mfa_hash = models.CharField(max_length = 50, null=True, blank=True)
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
def has_perm(self, perm, obj=None):
return self.is_superuser
def has_module_perms(self, app_label):
return self.is_superuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment