Commit e36a262b by Chris Green

making code work with SVN 12/19/07

parent f1e94819
......@@ -80,4 +80,4 @@ def verify(ticket, service):
username = page.readline().strip()
if verified == 'yes':
return username
return None
\ No newline at end of file
return None
......@@ -4,10 +4,10 @@ from django.conf import settings
class CASMiddleware(object):
def process_request(self, request):
error = "The Django CAS middleware requires authentication "
"middleware to be installed. Edit your MIDDLEWARE_CLASSES "
"setting to insert 'django.contrib.auth.middleware."
"AuthenticationMiddleware'."
error = """The Django CAS middleware requires authentication
middleware to be installed. Edit your MIDDLEWARE_CLASSES
setting to insert 'django.contrib.auth.middleware.
AuthenticationMiddleware'."""
assert hasattr(request, 'user'), error
def process_view(self, request, view_func, view_args, view_kwargs):
......@@ -17,17 +17,22 @@ class CASMiddleware(object):
return None
else:
admin_path = ['django', 'contrib', 'admin', 'views']
view_file = view_func.func_code.co_filename
try:
view_file = view_func.func_code.co_filename
except AttributeError:
# if we get a protected decororator that abstracts this away into something like _CheckLogin
view_file = view_func.view_func.func_code.co_filename
view_path = path.split(view_file)[0].split(path.sep)[-4:]
if view_path != admin_path:
return None
if request.user.is_authenticated():
if request.user.is_staff:
return None
else:
error = "<h1>Forbidden</h1>"
"<p>You do not have staff privileges.</p>"
error = "<h1>Forbidden</h1><p>You do not have staff privileges.</p>"
return HttpResponseForbidden(error)
field, url = settings.CAS_REDIRECT_FIELD_NAME, settings.CAS_LOGIN_URL
params = urlencode({field: request.get_full_path()})
return HttpResponseRedirect(url + '?' + params)
\ No newline at end of file
return HttpResponseRedirect(url + '?' + params)
from django.http import HttpResponseRedirect, HttpResponseForbidden, urlencode
from django.conf import settings
from django_cas import redirect_url, service_url
from django_cas import redirect_url, service_url, login_url
def login(request, next_page=None):
if not next_page:
......@@ -34,4 +34,4 @@ def logout(request, next_page=None):
logout(request)
if not next_page:
next_page = redirect_url(request)
return HttpResponseRedirect(next_page)
\ No newline at end of file
return HttpResponseRedirect(next_page)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment