Commit e10614e7 by Mark Sadecki Committed by Christine Lytwynec

adds support to auth_auth for redirecting

parent 44eaca08
...@@ -1799,6 +1799,7 @@ def auto_auth(request): ...@@ -1799,6 +1799,7 @@ def auto_auth(request):
* `course_id`: Enroll the student in the course with `course_id` * `course_id`: Enroll the student in the course with `course_id`
* `roles`: Comma-separated list of roles to grant the student in the course with `course_id` * `roles`: Comma-separated list of roles to grant the student in the course with `course_id`
* `no_login`: Define this to create the user but not login * `no_login`: Define this to create the user but not login
* `redirect`: Set to "true" will redirect to course if course_id is defined, otherwise it will redirect to dashboard
If username, email, or password are not provided, use If username, email, or password are not provided, use
randomly generated credentials. randomly generated credentials.
...@@ -1823,6 +1824,7 @@ def auto_auth(request): ...@@ -1823,6 +1824,7 @@ def auto_auth(request):
if course_id: if course_id:
course_key = CourseLocator.from_string(course_id) course_key = CourseLocator.from_string(course_id)
role_names = [v.strip() for v in request.GET.get('roles', '').split(',') if v.strip()] role_names = [v.strip() for v in request.GET.get('roles', '').split(',') if v.strip()]
redirect_when_done = request.GET.get('redirect', None)
login_when_done = 'no_login' not in request.GET login_when_done = 'no_login' not in request.GET
form = AccountCreationForm( form = AccountCreationForm(
...@@ -1885,7 +1887,15 @@ def auto_auth(request): ...@@ -1885,7 +1887,15 @@ def auto_auth(request):
create_comments_service_user(user) create_comments_service_user(user)
# Provide the user with a valid CSRF token # Provide the user with a valid CSRF token
# then return a 200 response # then return a 200 response unless redirect is true
if redirect_when_done:
# Redirect to course info page if course_id is known
if course_id:
return redirect(reverse('info', kwargs={'course_id': unicode(course_id)}))
# Otherwise redirect to dashboard
else:
return redirect(reverse('dashboard'))
if request.META.get('HTTP_ACCEPT') == 'application/json': if request.META.get('HTTP_ACCEPT') == 'application/json':
response = JsonResponse({ response = JsonResponse({
'created_status': u"Logged in" if login_when_done else "Created", 'created_status': u"Logged in" if login_when_done else "Created",
......
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