<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def form_valid(self, form):
 """ 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 """

        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)