django-cats/cats/views.py

24 lines
685 B
Python
Raw Normal View History

from django.contrib.auth import authenticate
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import redirect, render
from django.utils.translation import gettext as _
# Create your views here.
def certificate_login(request):
certificate = request.META.get('HTTP_X_SSL_CERT', None)
user = authenticate(request, encoded_certificate=certificate)
if not user:
return HttpResponseForbidden(_("you have not sent a valid client certificate"))
if "next" in request.GET:
return HttpResponseRedirect(request.GET["next"])
return redirect("home")
def home_page(request):
return render(request, "home.html")