NetTalk Central

Author Topic: Multi Tab - passing a user ID between tabs  (Read 4579 times)

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Multi Tab - passing a user ID between tabs
« on: April 02, 2015, 05:26:59 PM »
Hi, Bruce

Is there a way to save a user ID as 'super' session value like logged in and security level so that it won't be cleared when a new browser tab is opened?  A lot of my functions are authorized not just to by user level but by individual user.   As it is now,  once the user has logged in on one tab, the login page is skipped when they open the next tab so there is no way to get the user info.

I listened to the Mar 20 user group session where multi tab login was discussed, but I didn't hear a solution to this issue.  If it was resolved in the user group last week or today, my apologies and I will wait until they are posted.

Thanks so much.

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Multi Tab - passing a user ID between tabs
« Reply #1 on: April 12, 2015, 06:09:51 PM »
I have found a way to pass a user ID between tabs, but be forewarned,  it involves changes to the NetTalk source files with all the maintenance risk that entails.

The steps:

1) Add your user ID definition (presumably a string ) to the NetWebServerSessionQueueType  queue in NetAll.inc

2) Using the Get/Set SessionLevel prototypes and procedures as models, create Get/Set protos and procedures for both NetWebServer and NetWebServerWorker in NetWeb.inc and NetWeb.clw.

To reduce the maintenance risk,  I keep all the code in a separate file in SECTIONs that are INCLUDEd in the modified NT sources files.   I keep the modified NT source files in a different folder that is accessed first using the Redirection file,  so that a NetTalk update does not over write the changes.   You have to port your changes to the latest NT source code every time you update NetTalk.

Not a trivial matter  but without being able to pass a user ID to a new tab, I was limited to using multi tab just to enforcing the use of only one tab per session.   

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Multi Tab - passing a user ID between tabs
« Reply #2 on: April 12, 2015, 11:09:03 PM »
Hi Casey,

I think I maybe understand some of your question, but I think one point needs clarification;

>>  so that it won't be cleared when a new browser tab is opened?

As far as I am aware Session values are not cleared when a new tab opens. The existing session values (ie from whence it came) are cloned, and form the starting point for the new tab.

If you are _not_ experiencing this - ie for you session values are cleared when starting a new tab - then it's probably a good idea to show an example that gives that effect so it can be addressed.

cheers
Bruce

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Multi Tab - passing a user ID between tabs
« Reply #3 on: April 13, 2015, 11:53:44 AM »
Hi Bruce

I have attached a modified Web2 example that demonstrates the issue.    The app has a menu conditional on a session value ('ShowMenu3') being true.   The session value is set in the Validate Update method of MailBoxesFormControl.    Then, if you click the browser back button the new menu is displayed.  If you open a new tab and call the app, the session value is missing and the menu is hidden.

I assumed this was a functional limitation, rather than a bug because it makes sense and, except for the User ID issue, it works really well.

Thanks.   

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Multi Tab - passing a user ID between tabs
« Reply #4 on: April 13, 2015, 10:46:23 PM »
Hi Casey,

Thanks for the example - it showed that things weren't working quite the way I had in mind, which was thanks to a small change elsewhere in the code.

That said, there are some "boundaries" which come into play here. However before we begin let me refine your instructions somewhat;

>> Then, if you click the browser back button the new menu is displayed.

Browser Back buttons vary from browser to browser, and from context to context, so it's not a good idea to press them, or use them for example instructions. In your case I'd change this to "click the Home button in the menu".

Which leads us to the next issue;
If you simply open a new tab, and "type" in a URL then there's no "link" between the new tab and the old tab at that point. So the _first_ page generated is effectively "new". This page will effectively "start" a new set of session values from "nothing".

If however you "link" from one tab to another (say you Ctrl-Click the home button) then the link opens  a new tab, and the first page doesn't see any session values (so your menu won't appear) but then some javascript kicks in, and it recognizes that it was started by another tab, and so takes the session values from the other tab and uses it as the default here. This sounds more complex than it is, but basically means a user can "clone" a tab at a point.

anyway, thanks for the example - I'm not sure it will change your situation a lot (because of the menus) but it did clear up a problem on my side.

beck to your original question;

>> Is there a way to save a user ID as 'super' session value like logged in and security level so that it won't be cleared when a new browser tab is opened?  A lot of my functions are authorized not just to by user level but by individual user.   As it is now,  once the user has logged in on one tab, the login page is skipped when they open the next tab so there is no way to get the user info.

I'll see if there's a way to add this in without affecting existing things...

Cheers
Bruce


CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Multi Tab - passing a user ID between tabs
« Reply #5 on: April 14, 2015, 11:24:40 AM »
That's great, Bruce.  Thank you.  Even if the new methods are not used in the NT template code,  it will be a relief to avoid NT source code modifications.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Multi Tab - passing a user ID between tabs
« Reply #6 on: April 14, 2015, 10:38:25 PM »
I've added stuff to build 8.45 which should help.

Basically session values are stored in a queue using the SessionID / Name as the identifier. You don't actually pass the SessionID as that's handled for you. Multi-Tab support changed this so that the queue became Session ID / TabId / Name.
again TabId was handled (invisibly) for you.

In 8.45 I've added the ability for you to specify the "tabId" to use. The generated ones are (currently) 5 chars long, but there is space for up to 10, so if you used one that is say 4 chars long it won't clash with any generated one. Also the generated one only uses numbers and letters, so adding something else (like say a *) will guarantee there is no clash.

So, by specifying the TabId you can basically create your own (invisible) "tab" - and you can get, and set values in this "tab". So when you want to create or use a "cross tab" value, you can put it in this tab. For example;

p_web.SetSessionValue('name','value','picture','tabid')

Typically the picture is omitted so this might be

p_web.SetSessionValue('name','value', ,'tabid')
or
p_web.SSV('name','value', ,'tabid')

however do NOT use

p_web.SetSessionValue('name','value','tabid')

Omitting the extra , would be bad.

On the Get side it's a little simpler;

p_web.GetSessionValue('name','tabid')
or
p_web.GSV('name','tabid')

Other methods that have been extended are;
p_web.IfExistsSessionValue('name','tabid')
p_web.DeleteSessionValue('name','tabid')
p_web.GetSessionValueLength('name','tabid')
p_web.GetSessionValueFormat('name','tabid')
p_web.GetSessionPicture('name','tabid')


Of course you will need to change all your existing code where you want to store or retrieve these "cross tab" values, but all other places remain unchanged - unless specified the tab ID default remains as it was.

Cheers
Bruce