public.py 2.21 KB
Newer Older
David Baumgold committed
1 2 3
"""
Public views
"""
4
from django_future.csrf import ensure_csrf_cookie
Steve Strassmann committed
5
from django.core.context_processors import csrf
6
from django.core.urlresolvers import reverse
Steve Strassmann committed
7 8 9
from django.shortcuts import redirect
from django.conf import settings

David Baumgold committed
10
from edxmako.shortcuts import render_to_response
Steve Strassmann committed
11

12 13
from external_auth.views import (ssl_login_shortcut, ssl_get_cert_from_request,
                                 redirect_with_get)
14
from microsite_configuration import microsite
15

16
__all__ = ['signup', 'login_page', 'howitworks']
Steve Strassmann committed
17

18

19 20 21 22 23 24
@ensure_csrf_cookie
def signup(request):
    """
    Display the signup form.
    """
    csrf_token = csrf(request)['csrf_token']
25
    if request.user.is_authenticated():
26
        return redirect('/course/')
27
    if settings.FEATURES.get('AUTH_USE_CERTIFICATES_IMMEDIATE_SIGNUP'):
28 29
        # Redirect to course to login to process their certificate if SSL is enabled
        # and registration is disabled.
30
        return redirect_with_get('login', request.GET, False)
31

32
    return render_to_response('register.html', {'csrf': csrf_token})
33 34 35 36 37 38 39 40 41


@ssl_login_shortcut
@ensure_csrf_cookie
def login_page(request):
    """
    Display the login form.
    """
    csrf_token = csrf(request)['csrf_token']
42
    if (settings.FEATURES['AUTH_USE_CERTIFICATES'] and
43 44 45 46
            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.
47 48 49 50
        next_url = request.GET.get('next')
        if next_url:
            return redirect(next_url)
        else:
51
            return redirect('/course/')
52 53 54 55
    if settings.FEATURES.get('AUTH_USE_CAS'):
        # If CAS is enabled, redirect auth handling to there
        return redirect(reverse('cas-login'))

56 57 58 59 60
    return render_to_response(
        'login.html',
        {
            'csrf': csrf_token,
            'forgot_password_link': "//{base}/login#forgot-password-modal".format(base=settings.LMS_BASE),
61
            'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME),
62 63
        }
    )
64 65 66


def howitworks(request):
David Baumgold committed
67
    "Proxy view"
68
    if request.user.is_authenticated():
69
        return redirect('/course/')
70 71
    else:
        return render_to_response('howitworks.html', {})