<s> from django . contrib . auth . models import ( AbstractBaseUser , BaseUserManager , <EOL> PermissionsMixin ) <EOL> from django . core . mail import send_mail <EOL> from django . db import models <EOL> from django . utils . http import urlquote <EOL> from django . utils import timezone <EOL> class EmailUserManager ( BaseUserManager ) : <EOL> def _create_user ( self , email , password , <EOL> is_staff , is_superuser , ** extra_fields ) : <EOL> """<STR_LIT>""" <EOL> now = timezone . now ( ) <EOL> if not email : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> email = self . normalize_email ( email ) <EOL> user = self . model ( <EOL> email = email , <EOL> is_staff = is_staff , is_active = True , <EOL> is_superuser = is_superuser , last_login = now , <EOL> date_joined = now , ** extra_fields <EOL> ) <EOL> user . set_password ( password ) <EOL> user . save ( using = self . _db ) <EOL> return user <EOL> def create_user ( self , username , email , password , ** extra_fields ) : <EOL> return self . _create_user ( email , password , False , False , <EOL> ** extra_fields ) <EOL> def create_superuser ( self , username , email , password , ** extra_fields ) : <EOL> return self . _create_user ( email , password , True , True , <EOL> ** extra_fields ) <EOL> class AbstractEmailUser ( AbstractBaseUser , PermissionsMixin ) : <EOL> """<STR_LIT>""" <EOL> email = models . EmailField ( <EOL> '<STR_LIT>' , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> unique = True , <EOL> help_text = "<STR_LIT>" <EOL> ) <EOL> first_name = models . CharField ( <EOL> '<STR_LIT>' , <EOL> max_length = <NUM_LIT:30> , <EOL> blank = True <EOL> ) <EOL> last_name = models . CharField ( <EOL> '<STR_LIT>' , <EOL> max_length = <NUM_LIT:30> , <EOL> blank = True <EOL> ) <EOL> is_staff = models . BooleanField ( <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> help_text = '<STR_LIT>' <EOL> ) <EOL> is_active = models . BooleanField ( <EOL> '<STR_LIT>' , <EOL> default = True , <EOL> help_text = '<STR_LIT>' <EOL> ) <EOL> date_joined = models . DateTimeField ( '<STR_LIT>' , default = timezone . now ) <EOL> objects = EmailUserManager ( ) <EOL> USERNAME_FIELD = '<STR_LIT:email>' <EOL> REQUIRED_FIELDS = [ ] <EOL> class Meta : <EOL> verbose_name = '<STR_LIT:user>' <EOL> verbose_name_plural = '<STR_LIT>' <EOL> abstract = True <EOL> def get_absolute_url ( self ) : <EOL> return "<STR_LIT>" % urlquote ( self . pk ) <EOL> def get_full_name ( self ) : <EOL> """<STR_LIT>""" <EOL> full_name = '<STR_LIT>' % ( self . first_name , self . last_name ) <EOL> return full_name . strip ( ) <EOL> def get_short_name ( self ) : <EOL> "<STR_LIT>" <EOL> return self . first_name <EOL> def email_user ( self , subject , message , from_email = None ) : <EOL> """<STR_LIT>""" <EOL> send_mail ( subject , message , from_email , [ self . email ] ) <EOL> class EmailUser ( AbstractEmailUser ) : <EOL> """<STR_LIT>""" </s>
