Check if user has an active session


(Neil) #1

Hello,

I’m writing a page that uses jQuery to fire an ajax call from a matrix page to another matrix page. This works fine except when the user’s session has expired and the jQuery call (which is hitting a page you need to be logged in to see) just hangs. Our security team insist on the user session being ended after 10 mins of inactivity.

is it possible to either
a) redirect a user back to the homepage when their session has expired?
b) Use matrix keywords to see if there’s an active session?

Many thanks, Neil

Matrix Version: 5.4.3


(Bart Banda) #2

Seeing as you are on 5.4.3.0, you can use the %globals_user_is_logged_in% keyword to check if the current user is logged in or not.

%globals_user_is_logged_in%
Boolean keyword that either prints 
1
 if the current user is logged in, or 
0
 if they are not. You can use this in conditional keyword blocks to print dynamic content based on the user's login status:
%begin_globals_user_is_logged_in% <p>Welcome <strong>%globals_user_name%</strong></p> %else_globals% <p><a href="/_login">Click here to log in</a></p> %end_globals%

(Neil) #3

Cheers Bart. That doesn’t seem to work exactly for us as we use OAUTH accounts but just checking the user has an email is perfectly fine way of doing it.


(Bart Banda) #4

Hmmm, if you are using the OAuth Account Manager it should still work as the users are still created as normal matrix users. But good to hear that checking for email address also works for you.