Logic Machine Forum
Save the last login in object - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Save the last login in object (/showthread.php?tid=4025)



Save the last login in object - Fahd - 28.04.2022

Hi, 

I want to display the date/time of the user when of his  last logged into  the LM5,

For example, I've 5 users

User 1 : date/time (virtual object)
User 2 : date/time (virtual object)
....

So, I want a script that could write the date/time in a virtual object of each user.

Is it possible?
Thanks in advance


RE: Save the last login in object - admin - 29.04.2022

Create a scheduled script that runs as often as you want this data to be updated. Object type should be 250 byte string. Users are referenced by their login.

Code:
items = db:getall([[
  SELECT login, MAX(created) accessed
  FROM user_logs
  WHERE failed IS NULL or failed=0
  GROUP BY login
]])

logs = {}

for _, item in ipairs(items) do
  logs[ item.login ] = os.date('%c', item.accessed)
end

grp.checkupdate('1/1/1', logs.admin)
grp.checkupdate('1/1/2', logs.some_other_user)
grp.checkupdate('1/1/3', logs.another_user)



RE: Save the last login in object - Fahd - 29.04.2022

(29.04.2022, 11:15)admin Wrote: Create a scheduled script that runs as often as you want this data to be updated. Object type should be 250 byte string. Users are referenced by their login.

Code:
items = db:getall([[
  SELECT login, MAX(created) accessed
  FROM user_logs
  WHERE failed IS NULL or failed=0
  GROUP BY login
]])

logs = {}

for _, item in ipairs(items) do
  logs[ item.login ] = os.date('%c', item.accessed)
end

grp.checkupdate('1/1/1', logs.admin)
grp.checkupdate('1/1/2', logs.some_other_user)
grp.checkupdate('1/1/3', logs.another_user)
Your support is just amazing guys, 

THANKS A MILLION  Big Grin