def login(request): if request.user.is_authenticated(): return HttpResponseRedirect(reverse('users:profile')) # Get referer for redirect # Make sure that the referrer is a local path. if 'next' in request.GET: next_page = get_url_local_path(request.GET['next']) else: next_page = get_url_local_path(request.META.get('HTTP_REFERER', reverse('users:profile'))) # Test django login form if request.method == "POST": djangoform = DjangoLoginForm(request.POST) if djangoform.is_valid(): djangoform.login(request) return HttpResponseRedirect(djangoform.cleaned_data['next']) else: djangoform = DjangoLoginForm(next=next_page) # Openid login form # The form will be handled elsewhere; this is only for rendering the form. openidform = OpenIDLoginForm(next=next_page) # Render response return render(request, "users/login.html", { 'djangoform': djangoform, 'openidform': openidform, 'next': next_page, 'AUTH_METHODS': AUTH_METHODS })
def clean_next(self): return get_url_local_path(self.cleaned_data['next'])