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
9220c4d8
Commit
9220c4d8
authored
Mar 30, 2016
by
Amir Qayyum Khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed 500 error in case of user's profile not found when login/logout with CAS
parent
d9ad47c9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
4 deletions
+52
-4
common/djangoapps/external_auth/views.py
+4
-3
common/djangoapps/student/models.py
+6
-1
common/djangoapps/student/tests/test_login.py
+42
-0
No files found.
common/djangoapps/external_auth/views.py
View file @
9220c4d8
...
...
@@ -478,9 +478,10 @@ def cas_login(request, next_page=None, required=False):
if
request
.
user
.
is_authenticated
():
user
=
request
.
user
if
not
UserProfile
.
objects
.
filter
(
user
=
user
):
user_profile
=
UserProfile
(
name
=
user
.
username
,
user
=
user
)
user_profile
.
save
()
UserProfile
.
objects
.
get_or_create
(
user
=
user
,
defaults
=
{
'name'
:
user
.
username
}
)
return
ret
...
...
common/djangoapps/student/models.py
View file @
9220c4d8
...
...
@@ -1799,7 +1799,12 @@ def enforce_single_login(sender, request, user, signal, **kwargs): # pylint:
else
:
key
=
None
if
user
:
user
.
profile
.
set_login_session
(
key
)
user_profile
,
__
=
UserProfile
.
objects
.
get_or_create
(
user
=
user
,
defaults
=
{
'name'
:
user
.
username
}
)
if
user_profile
:
user
.
profile
.
set_login_session
(
key
)
class
DashboardConfiguration
(
ConfigurationModel
):
...
...
common/djangoapps/student/tests/test_login.py
View file @
9220c4d8
...
...
@@ -273,6 +273,48 @@ class LoginTest(TestCase):
self
.
assertEqual
(
response
.
status_code
,
302
)
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
'PREVENT_CONCURRENT_LOGINS'
:
True
})
def
test_single_session_with_no_user_profile
(
self
):
"""
Assert that user login with cas (Central Authentication Service) is
redirect to dashboard in case of lms or upload_transcripts in case of
cms
"""
user
=
UserFactory
.
build
(
username
=
'tester'
,
email
=
'tester@edx.org'
)
user
.
set_password
(
'test_password'
)
user
.
save
()
# Assert that no profile is created.
self
.
assertFalse
(
hasattr
(
user
,
'profile'
))
creds
=
{
'email'
:
'tester@edx.org'
,
'password'
:
'test_password'
}
client1
=
Client
()
client2
=
Client
()
response
=
client1
.
post
(
self
.
url
,
creds
)
self
.
_assert_response
(
response
,
success
=
True
)
# Reload the user from the database
user
=
User
.
objects
.
get
(
pk
=
user
.
pk
)
# Assert that profile is created.
self
.
assertTrue
(
hasattr
(
user
,
'profile'
))
# second login should log out the first
response
=
client2
.
post
(
self
.
url
,
creds
)
self
.
_assert_response
(
response
,
success
=
True
)
try
:
# this test can be run with either lms or studio settings
# since studio does not have a dashboard url, we should
# look for another url that is login_required, in that case
url
=
reverse
(
'dashboard'
)
except
NoReverseMatch
:
url
=
reverse
(
'upload_transcripts'
)
response
=
client1
.
get
(
url
)
# client1 will be logged out
self
.
assertEqual
(
response
.
status_code
,
302
)
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
'PREVENT_CONCURRENT_LOGINS'
:
True
})
def
test_single_session_with_url_not_having_login_required_decorator
(
self
):
# accessing logout url as it does not have login-required decorator it will avoid redirect
# and go inside the enforce_single_login
...
...
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