NetTalk Central

Author Topic: How to link session to user  (Read 5712 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
How to link session to user
« on: June 09, 2019, 06:27:56 AM »
Hi, how to link a session to a user and avoid the session to be deleted?
The idea is that if the user is disconnected, when login again it has the same session values.
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: How to link session to user
« Reply #1 on: June 10, 2019, 12:51:42 AM »
Hi Alberto,

I think you maybe want to refine your question a bit, because as it stands it doesn't really "have any meaning".

>> The idea is that if the user is disconnected,

Users cannot be disconnected, because there is no "connection" between the browser and the server. The browser works on a "request / response" model - in other words it makes a connection, sends a request, gets a response, and closes the connection.

>> when login again it has the same session values.

After some period of time that you set (15 mins by default) if there is no activity then the session will be deleted on the server side. If they login again after that they will start a new session. Since the old session has been deleted there are no "old session values".

So explain a bit more what you have in mind and let's go from there.

cheers
Bruce

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: How to link session to user
« Reply #2 on: June 10, 2019, 04:02:00 AM »
Ok, I want the next time the user logs in to have the same session values it had before.
John logs in today, left the office, the session times out and its deleted, tomorrow John logs in again and he needs to be in the same session that yesterday.
I think its something similar to what you do with the creation of xxxxx.Session.xml
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: How to link session to user
« Reply #3 on: June 10, 2019, 11:21:51 PM »
Hi Alberto,

ok, let's follow the thought through a bit.

a) when a session is deleted, you want to dump that session to disk, or a data table, linked to the user name.
b) when the user starts again (with the same sessionID?) it should read that file or data table.
c) you need to store the sessionID between runs of the IDE.

Of course a "session" is a lot more than just session values. Internally there's a SettingsQueue (mostly for forms), a Browse ID Queue (mostly for visible browses), a Channel queue (for websockets) and so on. But I'm guessing you can ignore most of those. Also you probably don't want to fiddle with the SessionQueue itself, just the Session Data queue.

c) is the easiest one to sort out. In the WebServer procedure set the property
s_web.PreserveSessionId = today() + 30
You'll want to update this value every day. This preserves the cookie in the browser for 30 days.

b) You'd add code here to WebHandler, NewSession method, after the parent call.

a) I think here you'd need to be careful. In the webserver, using the critical section (s_web._Wait() and s_web._Release()). Check out the _DeleteSession code in netweb.clw to see what it's doing. You'd embed in the WebServer, before the parent call.

cheers
Bruce
 

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: How to link session to user
« Reply #4 on: June 11, 2019, 05:28:37 AM »
a and b can this be made the same way you do with the save and load of the xxxxx.Session.xml, may be saving a UserId.Session.xml and load it again using the userId no matter what the sessionid is?
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: How to link session to user
« Reply #5 on: June 11, 2019, 10:11:12 PM »
a) would be different because dumping all the sessions is just an xml.save, whereas dumping one session would require filtering records out of the queue.
b) would be a simple load I guess (depending on how you saved it.)

cheers
Bruce