Simple FastCGI authorizer view

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def auth(request, path):
    from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
    from django.utils.html import escape
    if request.user.is_anonymous():
        # If not logged in, redirect to login page
        return HttpResponseRedirect(reverse("login") + "?next=/" + escape(path))
    elif request.user.has_perm("some.perm"):
        # If allowed, then return empty "200 OK" response, and
        # set REQUEST_USER.
        result = HttpResponse()
        result['Variable-REMOTE_USER'] = request.user.username
        return result
    else:
        # Otherwise, a user who isn't allowed.
        result = HttpResponseForbidden()
        result.write("Access denied")
        return result

More like this

  1. Run Django as a FastCGI authorizer by cme 4 years, 6 months ago
  2. FreeBSD rc.d FastCGI Script by davidblewett 4 years, 8 months ago
  3. Digest authentication for Piston by erikwright 3 years, 4 months ago
  4. django under apache / mod_fcgid by mike_45 4 years, 3 months ago
  5. Django with Fast CGI (Server Conf) by jackoder 3 years ago

Comments

(Forgotten your password?)