Commit 58cf539c by Brodie Rao

Implemented CAS_RETRY_LOGIN

parent 1c70294e
...@@ -55,6 +55,8 @@ Optional settings include: ...@@ -55,6 +55,8 @@ Optional settings include:
won't log the user out of CAS as well. won't log the user out of CAS as well.
* `CAS_REDIRECT_URL`: Where to send a user after logging in or out if * `CAS_REDIRECT_URL`: Where to send a user after logging in or out if
there is no referrer and no next page set. Default is `/`. there is no referrer and no next page set. Default is `/`.
* `CAS_RETRY_LOGIN`: If `True` and an unknown or invalid ticket is
received, the user is redirected back to the login page.
* `CAS_VERSION`: The CAS protocol version to use. `'1'` and `'2'` are * `CAS_VERSION`: The CAS protocol version to use. `'1'` and `'2'` are
supported, with `'2'` being the default. supported, with `'2'` being the default.
......
...@@ -10,6 +10,7 @@ _DEFAULTS = { ...@@ -10,6 +10,7 @@ _DEFAULTS = {
'CAS_IGNORE_REFERER': False, 'CAS_IGNORE_REFERER': False,
'CAS_LOGOUT_COMPLETELY': True, 'CAS_LOGOUT_COMPLETELY': True,
'CAS_REDIRECT_URL': '/', 'CAS_REDIRECT_URL': '/',
'CAS_RETRY_LOGIN': False,
'CAS_SERVER_URL': None, 'CAS_SERVER_URL': None,
'CAS_VERSION': '2', 'CAS_VERSION': '2',
} }
......
...@@ -62,7 +62,7 @@ def _logout_url(request, next_page=None): ...@@ -62,7 +62,7 @@ def _logout_url(request, next_page=None):
return url return url
def login(request, next_page=None): def login(request, next_page=None, required=False):
"""Forwards to CAS login URL or verifies CAS ticket""" """Forwards to CAS login URL or verifies CAS ticket"""
if not next_page: if not next_page:
...@@ -82,6 +82,8 @@ def login(request, next_page=None): ...@@ -82,6 +82,8 @@ def login(request, next_page=None):
message = "Login succeeded. Welcome, %s." % name message = "Login succeeded. Welcome, %s." % name
user.message_set.create(message=message) user.message_set.create(message=message)
return HttpResponseRedirect(next_page) return HttpResponseRedirect(next_page)
elif settings.CAS_RETRY_LOGIN or required:
return HttpResponseRedirect(_login_url(service))
else: else:
error = "<h1>Forbidden</h1><p>Login failed.</p>" error = "<h1>Forbidden</h1><p>Login failed.</p>"
return HttpResponseForbidden(error) return HttpResponseForbidden(error)
......
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