title: Custom authentication backend. Django
body: <p>I would like to create an authentication backend that allows users to log_in only using their email (no username, no password).</p>
  
  <p>Here is what I tried.</p>
  
  <p>backends.py:</p>
  
  <pre><code>from django.conf import settings
  from django.contrib.auth.models import User
  
  class EmailAuthBackend(object):    
      def authenticate(self, username=None, password=None):
          try:
              user = User.objects.get(email=username)
              if user:
                  return user
          except User.DoesNotExist:
              return None 
  </code></pre>
  
  <p>settings.py:</p>
  
  <pre><code>  AUTHENTICATION_BACKENDS = (
         'path_to.backends.EmailAuthBackend',
         'django.contrib.auth.backends.ModelBackend',
        )
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>   &lt;form  method="post" action="{% url myproject.views.test %}"&gt;
      {% csrf_token %}
  
          &lt;input type="text" name="email" value=""/&gt;
  
      &lt;button type="submit"&gt;Valider&lt;/button&gt;
  
      &lt;/form&gt;
  </code></pre>
  
  <p>view:</p>
  
  <pre><code> def test(request):
      email = ''
      if 'email' in request.POST:
          email = request.POST.get('email')
          if not User.objects.filter(email=email):
              User.objects.create(email=email)
          user = authenticate(username=email)
          if user is not None:
              if user.is_active:
                  auth_login(request, user)
      return HttpResponseRedirect(reverse('home'))
  </code></pre>
  
  <p>It doesn't work, the user is not authenticated. And I also have this error when I go to the /admin:</p>
  
  <pre><code>    AttributeError at /admin/logout/
      'EmailAuthBackend' object has no attribute 'get_user'
  </code></pre>