2016-09-19 20:55:18 +08:00
|
|
|
from django.contrib.auth.base_user import AbstractBaseUser
|
|
|
|
from django.contrib.auth.models import BaseUserManager
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class CustomEmailFieldUserManager(BaseUserManager):
|
|
|
|
def create_user(self, username, password, email):
|
|
|
|
user = self.model(username=username)
|
|
|
|
user.set_password(password)
|
|
|
|
user.email_address = email
|
|
|
|
user.save(using=self._db)
|
|
|
|
return user
|
|
|
|
|
|
|
|
|
|
|
|
class CustomEmailField(AbstractBaseUser):
|
|
|
|
username = models.CharField(max_length=255)
|
|
|
|
password = models.CharField(max_length=255)
|
2016-05-16 09:54:03 +08:00
|
|
|
email_address = models.EmailField(null=True)
|
2016-09-19 20:55:18 +08:00
|
|
|
is_active = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
EMAIL_FIELD = 'email_address'
|
2017-08-18 05:08:56 +08:00
|
|
|
USERNAME_FIELD = 'username'
|
2016-09-19 20:55:18 +08:00
|
|
|
|
|
|
|
objects = CustomEmailFieldUserManager()
|