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
7c78a099
Commit
7c78a099
authored
Dec 04, 2014
by
stephensanchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code review comments
parent
79ca56c3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
93 deletions
+51
-93
common/djangoapps/enrollment/views.py
+1
-46
common/djangoapps/user_api/tests/test_views.py
+1
-1
common/djangoapps/user_api/views.py
+1
-46
common/djangoapps/util/authentication.py
+48
-0
No files found.
common/djangoapps/enrollment/views.py
View file @
7c78a099
...
...
@@ -11,6 +11,7 @@ from rest_framework.response import Response
from
rest_framework.throttling
import
UserRateThrottle
from
enrollment
import
api
from
student.models
import
NonExistentCourseError
,
CourseEnrollmentException
from
util.authentication
import
SessionAuthenticationAllowInactiveUser
class
EnrollmentUserThrottle
(
UserRateThrottle
):
...
...
@@ -19,52 +20,6 @@ class EnrollmentUserThrottle(UserRateThrottle):
rate
=
'50/second'
class
SessionAuthenticationAllowInactiveUser
(
SessionAuthentication
):
"""Ensure that the user is logged in, but do not require the account to be active.
We use this in the special case that a user has created an account,
but has not yet activated it. We still want to allow the user to
enroll in courses, so we remove the usual restriction
on session authentication that requires an active account.
You should use this authentication class ONLY for end-points that
it's safe for an unactived user to access. For example,
we can allow a user to update his/her own enrollments without
activating an account.
"""
def
authenticate
(
self
,
request
):
"""Authenticate the user, requiring a logged-in account and CSRF.
This is exactly the same as the `SessionAuthentication` implementation,
with the `user.is_active` check removed.
Args:
request (HttpRequest)
Returns:
Tuple of `(user, token)`
Raises:
PermissionDenied: The CSRF token check failed.
"""
# Get the underlying HttpRequest object
request
=
request
.
_request
# pylint: disable=protected-access
user
=
getattr
(
request
,
'user'
,
None
)
# Unauthenticated, CSRF validation not required
# This is where regular `SessionAuthentication` checks that the user is active.
# We have removed that check in this implementation.
if
not
user
:
return
None
self
.
enforce_csrf
(
request
)
# CSRF passed with authenticated user
return
(
user
,
None
)
@api_view
([
'GET'
])
@authentication_classes
((
OAuth2Authentication
,
SessionAuthentication
))
@permission_classes
((
IsAuthenticated
,))
...
...
common/djangoapps/user_api/tests/test_views.py
View file @
7c78a099
...
...
@@ -1528,7 +1528,7 @@ class UpdateEmailOptInTestCase(ApiTestCase):
self
.
assertHttpBadRequest
(
response
)
def
test_update_email_opt_in_inactive_user
(
self
):
"""Test that an inactive user can still update
email
."""
"""Test that an inactive user can still update
their email optin preference
."""
self
.
user
.
is_active
=
False
self
.
user
.
save
()
# Register, which should trigger an activation email
...
...
common/djangoapps/user_api/views.py
View file @
7c78a099
...
...
@@ -26,6 +26,7 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
from
edxmako.shortcuts
import
marketing_link
import
third_party_auth
from
util.authentication
import
SessionAuthenticationAllowInactiveUser
from
user_api.api
import
account
as
account_api
,
profile
as
profile_api
from
user_api.helpers
import
FormDescription
,
shim_student_view
,
require_post_params
...
...
@@ -47,52 +48,6 @@ class ApiKeyHeaderPermission(permissions.BasePermission):
)
class
SessionAuthenticationAllowInactiveUser
(
authentication
.
SessionAuthentication
):
"""Ensure that the user is logged in, but do not require the account to be active.
We use this in the special case that a user has created an account,
but has not yet activated it. We still want to allow the user to
enroll in courses, so we remove the usual restriction
on session authentication that requires an active account.
You should use this authentication class ONLY for end-points that
it's safe for an un-activated user to access. For example,
we can allow a user to update his/her own enrollments without
activating an account.
"""
def
authenticate
(
self
,
request
):
"""Authenticate the user, requiring a logged-in account and CSRF.
This is exactly the same as the `SessionAuthentication` implementation,
with the `user.is_active` check removed.
Args:
request (HttpRequest)
Returns:
Tuple of `(user, token)`
Raises:
PermissionDenied: The CSRF token check failed.
"""
# Get the underlying HttpRequest object
request
=
request
.
_request
# pylint: disable=protected-access
user
=
getattr
(
request
,
'user'
,
None
)
# Unauthenticated, CSRF validation not required
# This is where regular `SessionAuthentication` checks that the user is active.
# We have removed that check in this implementation.
if
not
user
:
return
None
self
.
enforce_csrf
(
request
)
# CSRF passed with authenticated user
return
(
user
,
None
)
class
LoginSessionView
(
APIView
):
"""HTTP end-points for logging in users. """
...
...
common/djangoapps/util/authentication.py
0 → 100644
View file @
7c78a099
""" Common Authentication Handlers used across projects. """
from
rest_framework
import
authentication
class
SessionAuthenticationAllowInactiveUser
(
authentication
.
SessionAuthentication
):
"""Ensure that the user is logged in, but do not require the account to be active.
We use this in the special case that a user has created an account,
but has not yet activated it. We still want to allow the user to
enroll in courses, so we remove the usual restriction
on session authentication that requires an active account.
You should use this authentication class ONLY for end-points that
it's safe for an un-activated user to access. For example,
we can allow a user to update his/her own enrollments without
activating an account.
"""
def
authenticate
(
self
,
request
):
"""Authenticate the user, requiring a logged-in account and CSRF.
This is exactly the same as the `SessionAuthentication` implementation,
with the `user.is_active` check removed.
Args:
request (HttpRequest)
Returns:
Tuple of `(user, token)`
Raises:
PermissionDenied: The CSRF token check failed.
"""
# Get the underlying HttpRequest object
request
=
request
.
_request
# pylint: disable=protected-access
user
=
getattr
(
request
,
'user'
,
None
)
# Unauthenticated, CSRF validation not required
# This is where regular `SessionAuthentication` checks that the user is active.
# We have removed that check in this implementation.
if
not
user
:
return
None
self
.
enforce_csrf
(
request
)
# CSRF passed with authenticated user
return
(
user
,
None
)
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