code: def form_valid(self, form):
          
          redirect_to = self.request.POST.get('next', '')
          auth.login(self.request, form.user_cache)
          # check if next is a valid url
          if not is_safe_url(redirect_to, self.request.get_host()):
              return super(WebmailLoginView, self).form_valid(form)
          else:
              return redirect(redirect_to)
docs: This method is executed when submitted form is valid.
  
          It redirects to ``success_url`` if no ``next`` url is provided.
          Otherwise it redirects to ``next`` url.
  
          :param form: ``forms.Form`` instance
          :return: ``HttpResponse`` instance