Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
02485be3
Commit
02485be3
authored
Nov 12, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up redirect logic
parent
34dd4e59
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
17 deletions
+18
-17
common/djangoapps/user_api/helpers.py
+15
-10
common/djangoapps/user_api/tests/test_helpers.py
+3
-3
lms/static/js/student_account/views/RegisterView.js
+0
-4
No files found.
common/djangoapps/user_api/helpers.py
View file @
02485be3
...
...
@@ -323,9 +323,6 @@ def shim_student_view(view_func, check_logged_in=False):
(instead of always using status 200, but setting "success" to False in
the JSON-serialized content of the response)
* Use status code 302 for redirects instead of
"redirect_url" in the JSON-serialized content of the response.
* Use status code 403 to indicate a login failure.
The shim will preserve any cookies set by the view.
...
...
@@ -389,17 +386,30 @@ def shim_student_view(view_func, check_logged_in=False):
# Most responses from this view are JSON-encoded
# dictionaries with keys "success", "value", and
# (sometimes) "redirect_url".
#
# We want to communicate some of this information
# using HTTP status codes instead.
#
# We ignore the "redirect_url" parameter, because we don't need it:
# 1) It's used to redirect on change enrollment, which
# our client will handle directly
# (that's why we strip out the enrollment params from the request)
# 2) It's used by third party auth when a user has already successfully
# authenticated and we're not sending login credentials. However,
# this case is never encountered in practice: on the old login page,
# the login form would be submitted directly, so third party auth
# would always be "trumped" by first party auth. If a user has
# successfully authenticated with us, we redirect them to the dashboard
# regardless of how they authenticated; and if a user is completing
# the third party auth pipeline, we redirect them from the pipeline
# completion end-point directly.
try
:
response_dict
=
json
.
loads
(
response
.
content
)
msg
=
response_dict
.
get
(
"value"
,
u""
)
redirect_url
=
response_dict
.
get
(
"redirect_url"
)
or
response_dict
.
get
(
"redirect"
)
success
=
response_dict
.
get
(
"success"
)
except
(
ValueError
,
TypeError
):
msg
=
response
.
content
success
=
True
redirect_url
=
None
# If the user is not authenticated when we expect them to be
# send the appropriate status code.
...
...
@@ -426,11 +436,6 @@ def shim_student_view(view_func, check_logged_in=False):
response
.
status_code
=
403
response
.
content
=
msg
# If the view wants to redirect us, send a status 302
elif
redirect_url
is
not
None
:
response
.
status_code
=
302
response
[
'Location'
]
=
redirect_url
# If an error condition occurs, send a status 400
elif
response
.
status_code
!=
200
or
not
success
:
# The student views tend to send status 200 even when an error occurs
...
...
common/djangoapps/user_api/tests/test_helpers.py
View file @
02485be3
...
...
@@ -177,7 +177,7 @@ class StudentViewShimTest(TestCase):
self
.
assertEqual
(
response
.
content
,
"Not a JSON dict"
)
@ddt.data
(
"redirect"
,
"redirect_url"
)
def
test_redirect_from_json
(
self
,
redirect_key
):
def
test_
ignore_
redirect_from_json
(
self
,
redirect_key
):
view
=
self
.
_shimmed_view
(
HttpResponse
(
content
=
json
.
dumps
({
"success"
:
True
,
...
...
@@ -185,8 +185,8 @@ class StudentViewShimTest(TestCase):
}))
)
response
=
view
(
HttpRequest
())
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
[
'Location'
],
"/redirect
"
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
"
"
)
def
test_error_from_json
(
self
):
view
=
self
.
_shimmed_view
(
...
...
lms/static/js/student_account/views/RegisterView.js
View file @
02485be3
...
...
@@ -57,9 +57,5 @@ var edx = edx || {};
saveSuccess
:
function
()
{
this
.
trigger
(
'auth-complete'
);
},
redirect
:
function
(
url
)
{
window
.
location
.
href
=
url
;
}
});
})(
jQuery
,
_
,
gettext
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment