More fully integrate and test ssl external auth in CMS

This commit is contained in:
Carson Gee
2013-12-23 13:11:14 -05:00
parent 7e075eece1
commit 2bf6df23c8
4 changed files with 44 additions and 14 deletions

View File

@@ -3,13 +3,13 @@ Public views
"""
from django_future.csrf import ensure_csrf_cookie
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.conf import settings
from edxmako.shortcuts import render_to_response
from external_auth.views import ssl_login_shortcut
from external_auth.views import ssl_login_shortcut, ssl_get_cert_from_request
from microsite_configuration.middleware import MicrositeConfiguration
__all__ = ['signup', 'login_page', 'howitworks']
@@ -21,6 +21,13 @@ def signup(request):
Display the signup form.
"""
csrf_token = csrf(request)['csrf_token']
if request.user.is_authenticated():
return redirect('/course')
if settings.FEATURES.get('AUTH_USE_MIT_CERTIFICATES_IMMEDIATE_SIGNUP'):
# Redirect to course to login to process their certificate if SSL is enabled
# and registration is disabled.
return redirect(reverse('login'))
return render_to_response('signup.html', {'csrf': csrf_token})
@@ -31,6 +38,12 @@ def login_page(request):
Display the login form.
"""
csrf_token = csrf(request)['csrf_token']
if (settings.FEATURES['AUTH_USE_MIT_CERTIFICATES'] and
ssl_get_cert_from_request(request)):
# SSL login doesn't require a login view, so redirect
# to course now that the user is authenticated via
# the decorator.
return redirect('/course')
return render_to_response(
'login.html',
{