Commit 1c70294e by Brodie Rao

Minor refactoring

parent e0d8876b
...@@ -49,5 +49,4 @@ class CASMiddleware(object): ...@@ -49,5 +49,4 @@ class CASMiddleware(object):
'privileges.</p>') 'privileges.</p>')
return HttpResponseForbidden(error) return HttpResponseForbidden(error)
params = urlencode({REDIRECT_FIELD_NAME: request.get_full_path()}) params = urlencode({REDIRECT_FIELD_NAME: request.get_full_path()})
url = reverse(cas_login) return HttpResponseRedirect(reverse(cas_login) + '?' + params)
return HttpResponseRedirect(url + '?' + params)
...@@ -48,8 +48,7 @@ def _login_url(service): ...@@ -48,8 +48,7 @@ def _login_url(service):
params = {'service': service} params = {'service': service}
if settings.CAS_EXTRA_LOGIN_PARAMS: if settings.CAS_EXTRA_LOGIN_PARAMS:
params.update(settings.CAS_EXTRA_LOGIN_PARAMS) params.update(settings.CAS_EXTRA_LOGIN_PARAMS)
url = urljoin(settings.CAS_SERVER_URL, 'login') + '?' + urlencode(params) return urljoin(settings.CAS_SERVER_URL, 'login') + '?' + urlencode(params)
return url
def _logout_url(request, next_page=None): def _logout_url(request, next_page=None):
...@@ -75,10 +74,10 @@ def login(request, next_page=None): ...@@ -75,10 +74,10 @@ def login(request, next_page=None):
ticket = request.GET.get('ticket') ticket = request.GET.get('ticket')
service = _service_url(request, next_page) service = _service_url(request, next_page)
if ticket: if ticket:
from django.contrib.auth import authenticate, login from django.contrib import auth
user = authenticate(ticket=ticket, service=service) user = auth.authenticate(ticket=ticket, service=service)
if user is not None: if user is not None:
login(request, user) auth.login(request, user)
name = user.first_name or user.username name = user.first_name or user.username
message = "Login succeeded. Welcome, %s." % name message = "Login succeeded. Welcome, %s." % name
user.message_set.create(message=message) user.message_set.create(message=message)
...@@ -87,8 +86,7 @@ def login(request, next_page=None): ...@@ -87,8 +86,7 @@ def login(request, next_page=None):
error = "<h1>Forbidden</h1><p>Login failed.</p>" error = "<h1>Forbidden</h1><p>Login failed.</p>"
return HttpResponseForbidden(error) return HttpResponseForbidden(error)
else: else:
url = _login_url(service) return HttpResponseRedirect(_login_url(service))
return HttpResponseRedirect(url)
def logout(request, next_page=None): def logout(request, next_page=None):
......
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