cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

User last active Timestamp

pshashipreetham
17-Peridot

User last active Timestamp

Hi,

 

Is there a possibility to get a user last logged in time?

 

Thanks,

 

Shashi Preetham,
Email: psp316r@outlook.com,
Mobile: +91 8099838001.
ACCEPTED SOLUTION

Accepted Solutions

Hi @slangley 

 

Thanks for the Follow-up, and Thanks, @nmutter @TanmeyTWX @VladimirRosu, for all the replies. We have written the custom logic to record the User Active Status when a user opens the Landing Page.


Also, I have submitted the Idea:
A Option to Record the User last Active - PTC Community

Thanks,

Shashi Preetham,
Email: psp316r@outlook.com,
Mobile: +91 8099838001.

View solution in original post

10 REPLIES 10

Take a look this discussion - "Capture User Account Lockout Event": https://community.ptc.com/t5/ThingWorx-Developers/Capture-User-Account-Lockout-Event/td-p/642575

Hi @VladimirN ,

 

This is not what we are looking for, and we need the timestamp when the User last logged In.

 

Thanks,

Shashi Preetham,
Email: psp316r@outlook.com,
Mobile: +91 8099838001.

Try this example:

 

"1. Retrieve User Login Info: You can use the UserEntity service `GetLoginHistory` to get the login history for a user. This service returns a result set that contains information about user logins.

2. Filter Login History: Once you have the login history, you can filter it to get the last logged-in timestamp. The login history returned by `GetLoginHistory` is ordered by timestamp, so you can simply retrieve the first entry.

Here's an example of how you can achieve this using the ThingWorx REST API:

```
GET /Thingworx/Things/UserEntity/Services/GetLoginHistory?name=<username>&appKey=<your_app_key>
```
Replace `<username>` with the username of the user you want to retrieve the login history for, and `<your_app_key>` with your ThingWorx application key.

This API call will return a JSON response containing the login history for the user. You can parse the response to extract the timestamp of the last login".

Hi @VladimirN ,

 

GetLoginHistory, I can't see this in the snippets. Which version are you pointing out?

Thingworx Version I am using is 9.3.8

 

Thanks,

Shashi Preetham,
Email: psp316r@outlook.com,
Mobile: +91 8099838001.

I am not sure if this works in the case you use the SSO authenticator, but each User has a property called "lastConnection", that you would see if you create a service where you reference any User administrator, in its available properties.

In my non-SSO environment, this works correctly:

result = Users["Administrator"].lastConnection;

Hi @VladimirRosu,

 

Thanks for sharing the input. Based on it, what I found is:

  1. For Non-SSO Users: Users["Administrator"].lastConnection;
  2. For SSO Users: Users["Administrator"].GetLastModifiedDate();

But both ways, the Timestamp will reset when the Server is restarted.

 

Thanks,

Shashi Preetham,
Email: psp316r@outlook.com,
Mobile: +91 8099838001.

Hi Shashi,

 

To achieve your requirement, you need to develop your own logic on top of what @VladimirRosu mentioned above. I had developed the exact User usage report for every user login. You could trigger a service on master load on every user login which will do an entry to a stream so that you can get all the historic login attempts and then prepare the report.

No new information but there are these 2 PTC articles related:

How to display login or logout history in ThingWorx Platform

Simple User Login / Logout Audit Logger for ThingWorx which has an example attached to create an own Stream with the Login events

Unfortunately if you use TWX as an Resource Provider no event is executed it seems when a user accesses data.

 

I actually also need the information about last login date, to remove users which did not login for x months. Seems we need to create it on our own unfortunately.

slangley
23-Emerald II
(To:nmutter)

Hi @pshashipreetham & @nmutter.

 

Please feel free to submit a request for this functionality on the ThingWorx Ideas forum.  That will allow others to vote for it, which will increase its chances of being considered for a future release.

 

Regards.

 

--Sharon

Hi @slangley 

 

Thanks for the Follow-up, and Thanks, @nmutter @TanmeyTWX @VladimirRosu, for all the replies. We have written the custom logic to record the User Active Status when a user opens the Landing Page.


Also, I have submitted the Idea:
A Option to Record the User last Active - PTC Community

Thanks,

Shashi Preetham,
Email: psp316r@outlook.com,
Mobile: +91 8099838001.
Announcements


Top Tags