title: Authenticate users with both username and email
body: <p>I have extendted the <code>UserCreationForm</code> with email and other fields, so that I could authenticate a user with both its username and email.</p>
  
  <p>forms.py:</p>
  
  <pre><code>class UserCreationForm(UserCreationForm):
  
      class Meta:
          model = User
          fields = ('first_name', 'last_name', 'username', 'email',)
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>def auth_view(request):
      username = request.POST.get('username','')
      password = request.POST.get('password','')
      user = auth.authenticate(username=username, password=password)
  
      if user is not None:
          auth.login(request, user)
          return HttpResponseRedirect('/')
      elif:
          user = auth.authenticate(email=username, password=password)
          if user is not None:
              auth.login(request, user)
              return HttpResponseRedirect('/')
      else:
          return HttpResponseRedirect('/accounts/invalid_login')
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>&lt;form action="/accounts/auth/" method="post"&gt;
      {%csrf_token%}
  
      &lt;label for="name"&gt;Email or Username:&lt;/label&gt;
      &lt;input type="text" name="name" id="name" value=""&gt;
      &lt;label for="password"&gt;Password:&lt;/label&gt;
      &lt;input type="password" name="password" id="password" value=""&gt;
  
      &lt;input type="submit" value="LOGIN"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In the views I tried giving both the <code>username</code> and <code>email</code> as input from the form as <code>name</code>, and check to see if username and password authenticate. If not then check whether email and password authenticate. But its not working. How do I solve this problem? Please kindly help me. Thank you.</p>