docs: def login(request, next_page=None, required=False, gateway=False):
      """
      Forwards to CAS login URL or verifies CAS ticket
  
      :param: request RequestObj
      :param: next_page Next page to redirect after login
      :param: required
      :param: gateway Gatewayed response
  
      """
  
      if not next_page:
          next_page = _redirect_url(request)
  
      try:
          # use callable for pre-django 2.0
          is_authenticated = request.user.is_authenticated()
      except TypeError:
          is_authenticated = request.user.is_authenticated
  
      if is_authenticated:
          return HttpResponseRedirect(next_page)
  
      ticket = request.GET.get('ticket')
  
      if gateway:
          service = _service_url(request, next_page, True)
      else:
          service = _service_url(request, next_page, False)
  
      if ticket:
          user = auth.authenticate(ticket=ticket, service=service)
  
          if user is not None:
  
              auth.login(request, user)
  
              if settings.CAS_PROXY_CALLBACK:
                  proxy_callback(request)
  
              return HttpResponseRedirect(next_page)
          elif settings.CAS_RETRY_LOGIN or required:
              if gateway:
                  return HttpResponseRedirect(_login_url(service, ticket, True))
              else:
                  return HttpResponseRedirect(_login_url(service, ticket, False))
          else:
              logger.warning('User has a valid ticket but not a valid session')
              # Has ticket, not session
  
              if gateway:
                  # Gatewayed responses should nto redirect.
                  return False
  
              if getattr(settings, 'CAS_CUSTOM_FORBIDDEN'):
                  return HttpResponseRedirect(reverse(settings.CAS_CUSTOM_FORBIDDEN) + "?" + request.META['QUERY_STRING'])
              else:
                  error = "<h1>Forbidden</h1><p>Login failed.</p>"
                  return HttpResponseForbidden(error)
      else:
          if gateway:
              return HttpResponseRedirect(_login_url(service, ticket, True))
          else:
              return HttpResponseRedirect(_login_url(service, ticket, False))