title: Login / register using phone or email for django, allauth integration
body: <p>I want to modify my django user model to allow phone or email registration / login. Using </p>
  
  <pre><code>USERNAME_FIELD = 'identifier'
  </code></pre>
  
  <p>If the user registers with phone number, the identifier will be its phone number, or email, vice versa. (If anyone think I should just assign some number as the identifier, let me know.)</p>
  
  <p>Here is my accounts.models: </p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
  from phonenumber_field.modelfields import PhoneNumberField
  
  class UserManager(BaseUserManager):
      def create_user(self, email, phone, password, **kwargs):
          """
          Creates and saves a Account with the given email or phone and password.
          """
          now = timezone.now()
          identifier = ''
          if not email:
              if not phone:
                  raise ValueError('Users must have a valid email or phone address.')
              else:
                  identifier = phone
          if not phone:
              if not email:
                  raise ValueError('Users must have a valid email or phone address.')
              else: 
                  email = self.normalize_email(email)
                  identifier = email
  
          user = self.model(email=email, phone=phone, 
                              identifier=identifier,
                              joined=now,
                              **kwargs
          )
  
          user.set_password(password)
          user.save(using=self._db)
          return user
  
      def create_superuser(self, email, password, **kwargs):
          user = self.model(
              email=email,
              is_staff=True,
              is_superuser=True,
              **kwargs
          )
          user.set_password(password)
          user.save(using=self._db)
          return user
  
  class User(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField(null=True, blank=True, unique=True)
      phone = PhoneNumberField(null=True, blank=True, unique=True)
      joined = models.DateTimeField(auto_now_add=True)
      first_name = models.CharField(max_length=200, null=True, blank=True)
      last_name = models.CharField(max_length=200, null=True, blank=True)
      is_staff = models.BooleanField(default=False)
      objects = UserManager()
      identifier = models.CharField(max_length=40, unique=True)
      USERNAME_FIELD = 'identifier'
  
      def get_username(self):
          return self.email
      def get_short_name(self):
          return self.first_name
      short_name = property(fget=get_short_name)
  </code></pre>
  
  <p>I'm not quite sure if this is the right way to approach user model, and I'm even more confused trying to integrate all-auth and rest-auth with it.  Right now, my gut tells me to just create everything on my own.  If anyone has any experience with all-auth integration so that it allows phone / email registration &amp; login, and whether I should try to fork it / just start from scratch, please let me know.</p>
  
  <p>So mainly these are my two questions:</p>
  
  <ol>
  <li>Can my user model be improved? </li>
  <li>Your thoughts on Allauth integration for phone &amp; email authentication.</li>
  </ol>