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
f006d03c
Commit
f006d03c
authored
Dec 27, 2014
by
Chris Dodge
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update the last_login timestamp when logging in
parent
055d378a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
lms/djangoapps/api_manager/sessions/tests.py
+12
-0
lms/djangoapps/api_manager/sessions/views.py
+5
-0
No files found.
lms/djangoapps/api_manager/sessions/tests.py
View file @
f006d03c
...
...
@@ -8,6 +8,7 @@ Run these tests @ Devstack:
from
random
import
randint
import
uuid
import
mock
from
datetime
import
datetime
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
...
...
@@ -77,8 +78,15 @@ class SessionsApiTests(TestCase):
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
response
=
self
.
do_post
(
self
.
base_users_uri
,
data
)
user_id
=
response
.
data
[
'id'
]
# get a copy of the User object, so we can compare timestamps
user1
=
User
.
objects
.
get
(
id
=
user_id
)
self
.
assertTrue
(
isinstance
(
user1
.
last_login
,
datetime
))
self
.
assertIsNotNone
(
user1
.
last_login
)
data
=
{
'username'
:
local_username
,
'password'
:
self
.
test_password
}
response
=
self
.
do_post
(
self
.
base_sessions_uri
,
data
)
user2
=
User
.
objects
.
get
(
id
=
user_id
)
self
.
assertEqual
(
response
.
status_code
,
201
)
self
.
assertGreater
(
len
(
response
.
data
[
'token'
]),
0
)
confirm_uri
=
self
.
test_server_prefix
+
self
.
base_sessions_uri
+
'/'
+
response
.
data
[
'token'
]
...
...
@@ -88,6 +96,10 @@ class SessionsApiTests(TestCase):
self
.
assertEqual
(
str
(
response
.
data
[
'user'
][
'username'
]),
local_username
)
self
.
assertEqual
(
response
.
data
[
'user'
][
'id'
],
user_id
)
# make sure the last_login timestamp was updated at the login operation
self
.
assertTrue
(
isinstance
(
user2
.
last_login
,
datetime
))
self
.
assertNotEqual
(
user1
.
last_login
,
user2
.
last_login
)
def
test_session_list_post_invalid
(
self
):
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
local_username
=
local_username
[
3
:
-
1
]
# username is a 32-character field
...
...
lms/djangoapps/api_manager/sessions/views.py
View file @
f006d03c
...
...
@@ -13,6 +13,7 @@ from django.utils.translation import ugettext as _
from
api_manager.permissions
import
SecureAPIView
from
rest_framework
import
status
from
rest_framework.response
import
Response
from
django.utils
import
timezone
from
util.bad_request_rate_limiter
import
BadRequestRateLimiter
...
...
@@ -119,6 +120,10 @@ class SessionsList(SecureAPIView):
response_data
[
'uri'
]
=
'{}/{}'
.
format
(
base_uri
,
new_session
.
session_key
)
response_status
=
status
.
HTTP_201_CREATED
# update the last_login fields in the auth_user table for this user
user
.
last_login
=
timezone
.
now
()
user
.
save
()
# add to audit log
AUDIT_LOG
.
info
(
u"API::User logged in successfully with user-id - {0}"
.
format
(
user
.
id
))
else
:
...
...
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