NetTalk Central

Author Topic: How to do an automatic logout?  (Read 5813 times)

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
How to do an automatic logout?
« on: March 30, 2009, 09:33:02 AM »
Hi all,

At the risk of sounding ignorant, yet again, here goes.

I would like to be able to logout the user automatically (embedded code) under certain conditions without ending the session.  How do I accomplish that?

Also, is it possible to logout the user after a time-out without ending the session?  Just want to force the user to login again if time has expired.

Thanks much,
Jill

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: How to do an automatic logout?
« Reply #1 on: March 30, 2009, 10:24:49 PM »
Hi Jill,

I can help with the first question.

Run this piece of code

p_web.SetSessionLoggedIn(0)

I also delete any login related session variables (not really necessary just habit I think)

p_web.DeleteSessionValue('_loginName')

Regarding the second question I usually have my session timeout set accordingly to achieve this. Not sure why you'd want a session to continue after you log them out!

Regards
Bill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to do an automatic logout?
« Reply #2 on: March 31, 2009, 01:54:10 AM »
Hi Jill,

Internally there's only one timeout, so if you wanted to add another one you'd have to do that manually.

Bill's comment on using p_web.SetSessionLoggedIn(0) is correct.

Cheers
Bruce

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #3 on: March 31, 2009, 08:13:55 AM »
Thanks, Bill, that does the trick!

But now when the procedure closes, the menu beneath it does not change.  The Logout button is still visible along with all of the menu options.  How do I get it to redisplay the menu?

Regards,
Jill

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: How to do an automatic logout?
« Reply #4 on: March 31, 2009, 04:24:10 PM »
Hi Jill,

It all depends upon how you want it to work.

I have a program that you can click on the Logout menu option. When they do that a small sexy centered screen thanks them for their patronage. I then have links on that screen for what they might need to do next.

To do this, just create a standard NetWebPage make it look nice. Add the logout code below into it (so when the page is called you get logged out). Meanwhile a pretty page will be displayed, overwriting whatever was on there browser before it.

The above is a nice clean why of doing it. However, sometimes you may want to force the user to a new page, whilst within an existing one. You can only do this if the existing one hasn't began rendering the HTML. To do this simple call the page within code and return after it.ie:

IF p_web.GSV('ShouldIBeSomeWhereElse') = 1
  MainPage(p_web)
  RETURN
.


Again this isn't safe to do if the page you are on has begum sending HTML to the browser, you'd get two pages mixed together in a mess.

Regards
Bill

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #5 on: April 01, 2009, 01:23:37 PM »
Thank you Bill and Bruce for your replies.

My application uses a Frame with MenuOnLeft, with a LoginForm control and a LogoutForm.  "Change Password" is in the menu (displayed only if logged in) and when clicked, the ChangePW form displays to the right of the menu and works properly.  However, after three tries entering an incorrect current password, I am now logging the user out thanks to your help and returning from the ChangePW procedure.  However, the MenuOnLeft should now be displaying only the LoginForm since p_web.getsessionloggedIn()=0 now.  But the LoginForm does not display and the Logout button is displayed instead and all of my menu options are still displayed also.  I would like to refresh the MenuOnLeft so that it will display properly.  How can I do that without opening a whole new browser page?

I hope you can understand my description.  I'm a brand new newbie.  I'm having good success with NetTalk so far except for some of these housekeeping things, probably due to my limited knowledge of both html and javascript.  Thanks for your help.

Jill

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: How to do an automatic logout?
« Reply #6 on: April 01, 2009, 07:03:51 PM »
This is from the help docs - not sure if it will do want you want.


W18: How do I refresh the page in another Frame

    Question:

    How do I refresh the page in another Frame when this frame loads?

    Answer:

    When you are sending a page to a browser you can embed JavaScript in the page.
    It doesn't matter too much where the Script is, but I usually put it at the bottom of the page, after the </form> statement.
    The code to for a frame to refresh looks like this

    <script> top.frames.top_fram.location.reload(true) </script>

    Where top_fram is the name of the frame you want to refresh.

    Here's an example that conditionally loads the top frame, or the left frame, depending on the existence of a local value.

    if p_web.IfExistsValue('loc:no')
      packet = clip(packet) & '<script> top.frames.top_fram.location.reload(true) </script>'
      packet = clip(packet) & '<script> top.frames.left_fram.location.reload(true) </script>'
    end

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to do an automatic logout?
« Reply #7 on: April 01, 2009, 09:01:08 PM »
Hi Jill,

Another approach is to not

>> and returning from the ChangePW procedure.

but rather to have the "save" button on the form call the FrameSet procedure, with the target set to '_top'. This will refresh _all_ the frames with the new logged in/out status.

Cheers
Bruce

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #8 on: April 02, 2009, 07:26:07 AM »
Hi Bruce,

Thanks for your help.  By "FrameSet" procedure you must be refering to FramePage?  (I copied from the examples.)  If I put 'FramePage' in for the URL and '_Top' in for the TargetFrame (for the Save button) it then opens up a whole new browser page and now there are two separate browser pages open with my app's framepage in them.  If I take out '_Top' and leave it blank, then when Save is clicked a new FramePage opens up inside the original FramePage with a whole new MenuOnLeft, etc.  In fact, if I leave the URL line for the Save button blank or enter anything other than 'IndexPage' in the URL line, clicking the Save button causes a new FramePage to be opened up within the original one.  Only 'IndexPage' in the URL seems to work at all properly for me.  I think there must be something set wrong somewhere in my app although I have checked all the settings in IndexPage, FramePage, MenuOnLeft, and ChangePWForm a thousand times and I can't see anything different from the examples.

If I don't have the URL set to 'IndexPage' for the Close buttons in all the other procedures that are called from the MenuOnLeft procedure I get the same weird result where the menu or the framepage is opened a second time within the original FramePage.  In fact if I continue running procedures it nests more FramePages!   Can you give me a hint of what might be causing this behavior?

I use IE7 and am testing on the LocalHost.

Thanks for any help you can give me.  By the way, I am looking forward to your Webinar tomorrow!

Cheers,
Jill

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #9 on: April 02, 2009, 07:31:03 AM »
Hi Kevin,

Thanks for your reply.  I found it in the docs yesterday and tried it.  Could not make it work.  I placed it in several different spots and it wouldn't work.  Maybe I just didn't hit on the right placement.

Regards,
Jill

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #10 on: April 02, 2009, 09:54:52 AM »
Hi again Bruce,

I went into the Accounts example App and added a Close button to the BrowseCustomers procedure and found that I must have the URL set to 'IndexPage' there as well or I get the same result as in my own app.  I can live with this just fine, but it still does not solve my original problem.  How can I get the MenuOnLeft procedure to reflect the logout that occurs in my ChangePWForm when the user was not able to enter the current password after three attempts?

Thanks,
Jill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to do an automatic logout?
« Reply #11 on: April 02, 2009, 08:30:35 PM »
Hi Jill,

the FramePage, yes. not that it should be set to _top not _Top. Frame names are case sensitive.

If that opens a new window on your browser (which it shouldn't) try _parent.

Cheers
Bruce

jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #12 on: April 03, 2009, 03:12:02 PM »
Thanks, Bruce!

'_parent' works well except that now when the user clicks the Save button and my embedded validation code finds an error and returns it to the user, the form has now replaced the FramePage and is alone in the browser, top & left.  Then when the user clicks the Save button and it leaves the form altogether, the FramePage redisplays reflecting the logout if logout has occured.  So it's much closer to what I wanted.  I would like to see if I could embed some code that would allow the form to be redisplayed in the Frame if it is returning validation errors.  Could you maybe give me a clue?  If not, I can live with this.

Excellent webinar today.  Very helpful.  Thanks so much.  I feel like I am making good progress now.

Cheers,
Jill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to do an automatic logout?
« Reply #13 on: April 03, 2009, 11:22:31 PM »

>> I would like to see if I could embed some code that would allow the form to be redisplayed in the Frame if it is returning validation errors.

The only way around this is slightly complicated.

Firstly - the browser doesn't tell the server where it plans to put the received page - and the server can't override it. The URL has the target set to "parent" so parent it will be.

So the only solution is to
a) set the page to return the _framepage_ if a validation error occurs and
b) set the framepage to include the form as one of the child pages.

Problem is, I don't think even this approach will allow the form to show "what is wrong".

There's an example, example 7 as a I recall, of the (b) part - ie conditional frames in a framepage.

For (a) I think you set the Retry variable.
p_web.SetValue('retry') = 'Framepage'

But as I say, I thin then the reason _why_ the page is invalid will not be displayed.

Cheers
Bruce



jkunes

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: How to do an automatic logout?
« Reply #14 on: April 06, 2009, 08:22:51 AM »
Bruce,

Thanks.  I plant to take a closer look at the examples again now that I am feeling more comfortable with NetTalk.

Cheers
Jill