from django.contrib.auth.models import PermissionsMixin, UserManager
from django.core import validators
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _


class User(PermissionsMixin, models.Model):
    username = models.CharField(
        _('username'),
        max_length=30,
        unique=True,
        db_index=True,
        validators=[
            validators.RegexValidator(r'^[a-zA-Z0-9_-]+$'),
        ],
        help_text=_('You can use a-z, 0-9, underscores, and hyphens.'),
    )
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    email = models.EmailField(_('email address'), max_length=63,
                              unique=True, db_index=True)
    is_staff = models.BooleanField(
        _('staff status'),
        default=False,
        help_text=_('Designates whether the user can log into this admin site.'),
    )
    is_active = models.BooleanField(
        _('active'),
        default=True,
        help_text=_(
            'Designates whether this user should be treated as active. '
            'Unselect this instead of deleting accounts.'
        ),
    )
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
    last_login = models.DateTimeField(_('last login'), blank=True, null=True)

    objects = UserManager()

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']

    class Meta:
        db_table = 'auth_user'

    def __str__(self):
        return self.username

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return True

    def get_full_name(self):
        raise NotImplementedError()

    def get_short_name(self):
        raise NotImplementedError()

    def get_session_auth_hash(self):
        key_salt = 'django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash'
        return salted_hmac(key_salt, self.password).hexdigest()

    def email_user(self, subject, message, from_email=None, **kwargs):
        send_mail(subject, message, from_email, [self.email], **kwargs)

@@ -1895,328 +1895,369 @@
 def 
-get_session_auth_hash(self):%0A        key_salt = 'django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash'%0A        return salted_hmac(key_salt, self.password).hexdigest()%0A%0A    def email_user(self, subject, message, from_email=None, **kwargs):%0A        send_mail(subject, message, from_email, %5Bself.email%5D, **kwargs)
+email_user(self, subject, message, from_email=None, **kwargs):%0A        send_mail(subject, message, from_email, %5Bself.email%5D, **kwargs)%0A%0A    def set_password(self, raw_password):%0A        pass%0A%0A    def check_password(self, raw_password):%0A        return False%0A%0A    def set_unusable_password(self):%0A        pass%0A%0A    def has_usable_password(self):%0A        return False
 %0A

add stub password methods to User model