title: How to make a login view for django custom user?
body: <p>I have made a custom user model using the AbstractUser , removed the username and replaced it with email and extended the model, tried creating superuser and it worked and also created some users by a signup form , logged in the admin interface and it worked however when tried to create a login form for the users it fails  </p>
  
  <p>I tried this but it didn't work</p>
  
  <pre><code>def LoginView(request):
      if request.method == 'POST':
          form = AuthenticationForm(data=request.POST)
          if form.is_valid():
              user = form.get_user()
              login(request,user)
              return redirect('accounts:login')
      else:
          form = AuthenticationForm()
      return render(request,'accounts/login.html', {'form':form})
  </code></pre>
  
  <p>then i tried this </p>
  
  <pre><code>class LoginView(FormView):
     form_class = AuthenticationForm
     template_name = 'login.html'
  
     def form_valid(self, form):
         email = form.cleaned_data['email']
         password = form.cleaned_data['password']
         user = authenticate(email=email, password=password)
  
      # Check here if the user is an admin
         if user is not None and user.is_active:
             login(self.request, user)
             return HttpResponseRedirect(self.success_url)
         else:
             return self.form_invalid(form)
  </code></pre>
  
  <p>Obviously i expect the user to be logged in
  i think the code in this post is badly formatted. mainly it's my fault as i'm new to this platform</p>