From 5d85fab28348319efaef122599ec135ff91cf878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s=20Rocha?= Date: Wed, 19 Dec 2012 18:48:30 -0500 Subject: [PATCH 1/2] Fix django auth login redirection The django authentication decorator login_required, redirects to settings.LOGIN_URL. If it is missing, it redirects to /accounts/login. We did not have the setting enable, not a proper page where to redirect. This cause users not logged in to see a 404 error when accessing courseware directly, by using a link or a bookmark. [#41499213] --- common/djangoapps/student/views.py | 12 ++++ lms/envs/common.py | 3 + lms/templates/accounts_login.html | 92 ++++++++++++++++++++++++++++++ lms/urls.py | 2 + 4 files changed, 109 insertions(+) create mode 100644 lms/templates/accounts_login.html diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 44877ef597..bcb3b664e7 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -333,6 +333,18 @@ def change_enrollment(request): return {'success': False, 'error': 'We weren\'t able to unenroll you. Please try again.'} +@ensure_csrf_cookie +def accounts_login(request, error=""): + + return_to = '' + + return render_to_response('accounts_login.html', { + 'error': error, + 'return_to': return_to + }) + + + # Need different levels of logging @ensure_csrf_cookie def login_user(request, error=""): diff --git a/lms/envs/common.py b/lms/envs/common.py index 1b1be28ead..26941f7e01 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -187,6 +187,9 @@ DEBUG_TRACK_LOG = False MITX_ROOT_URL = '' +LOGIN_REDIRECT_URL = MITX_ROOT_URL + '/accounts/login' +LOGIN_URL = MITX_ROOT_URL + '/accounts/login' + COURSE_NAME = "6.002_Spring_2012" COURSE_NUMBER = "6.002x" COURSE_TITLE = "Circuits and Electronics" diff --git a/lms/templates/accounts_login.html b/lms/templates/accounts_login.html new file mode 100644 index 0000000000..011ca643c6 --- /dev/null +++ b/lms/templates/accounts_login.html @@ -0,0 +1,92 @@ +<%! from django.core.urlresolvers import reverse %> +<%inherit file="main.html" /> +<%namespace name='static' file='static_content.html'/> + +<%block name="headextra"> + + + + + + diff --git a/lms/urls.py b/lms/urls.py index 92abdf794b..baa720028b 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -37,6 +37,8 @@ urlpatterns = ('', url(r'^event$', 'track.views.user_track'), url(r'^t/(?P