[Seaside] redirect user if session dead without clicking him at the page itself

Johan Brichau johan at inceptive.be
Thu Apr 20 17:15:37 UTC 2017


Hi Sabine,

If you include a period check, you automatically keep the session alive if the ‘check in’ interval is shorter than the session expiration duration.
If the session is dead, the callback cannot execute because it is no longer there, so you cannot write code that checks if the session is still alive from within you Seaside code on the server.

You can only do something on the client, if the Seaside session is reported to be ‘dead’ (i.e. when receiving an http response 403).
Using an error handler for the jquery ajax requests is the way we deal with those situations. It boils down to this:

        script:
            (html jQuery this load
                html: [ :r | … ];
		onError: (html javascript alias: handleError))
               interval: 30 seconds);
        with: [ html render: something].


function handleError( event, jqxhr, settings, thrownError ) {
	if(jqxhr.status == 403)
		window.location = '/‘;
}

Instead of writing this for each ajax callback, you can also set a global ajax handler on the document when the page loads: http://api.jquery.com/category/ajax/global-ajax-event-handlers/ <http://api.jquery.com/category/ajax/global-ajax-event-handlers/>
You might also want to take a look at this chapter: http://book.seaside.st/book/in-action/session/recovering <http://book.seaside.st/book/in-action/session/recovering> if you want to respond in a specific way when sessions have expired

Does this help you?

cheers
Johan

> On 20 Apr 2017, at 18:04, Sabine Manaa <manaa.sabine at gmail.com> wrote:
> 
> Hi,
> 
> is anyone having an idea for a solution of this problem: 
> 
> I want that my seaside web app redirects the user to another page (login page) if the session is "dead*". The special point I am looking for is: 
> 
> This should happen ALSO if the user does NOT click on this page or does something. Also if the user switches to another tab. 
> 
> So, if he comes back to the browser/to my apps tab, he should see a message "you have already been logged out".
> 
> I assume I have to periodically check if the session is alive and played around with 
> 
> html paragraph
>         script:
>             (html jQuery this load
>                 html: [ :r | "here check for session and if not there, redirect"
>                     (Array with: self currentPerson with: (self application sessions includes: self session))
>                         inspect ];
>                 interval: 30 seconds);
>         with: [ html render: something].
> 
> but if the session is dead, the code "here check ..." is no longer executed.
> I am not sure if this is the right idea...
> Anyone already implemented something like this?
> 
> I am not looking for a redirect after clicking somewhere in the app, I have this and it works fine. 
> 
> Regards
> Sabine
> 
> * I have read a little about "dead" sessions and know that they are collected away at unpredictable time. With "dead" I mean that if the user would click at the app, he would be transferred away.
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/seaside/attachments/20170420/3da5dc6f/attachment.html>


More information about the seaside mailing list