Thanks for the feedback,
What I ended up doing is not optimal but it works.
App Controller:
public function beforeFilter() {
if($this->request->is('ajax') &&( !$this->AuthUser->status())){
$response = array(
'login' => true,
'message' => 'You have been logged out. Please login to continue.');
$this->_ajaxResponse($response);
}
}
And in my js since most run off the same function for returning data:
Snip:
success: function(r){
forceLogin(r);
so if the forceLogin === true as determined in the JSON response it simply redirects to login
function forceLogin(r) {
if(r.login && (r.login === true)){
window.location.href="/login";
}
};
Still open to better ideas / methods but for now it works so that’s all that matters J
Dave
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Jeremy Burns : Class Outfit
Sent: Friday, September 06, 2013 1:35 AM
To: cake-php@googlegroups.com
Subject: Re: Ajax Login - Redirect Help
Don't know if this is the best way of handling this, but this is what I do: https://gist.github.com/classoutfit/6459420 It seems to work pretty well.
Jeremy Burns
Class Outfit
Mob: +44 (0) 7973 481949
Tel: +44 (0) 208 123 3822
Skype: jeremy_burns
classoutfit.com
On 5 Sep 2013, at 21:51, "Advantage+" <movepixels@gmail.com> wrote:
I have / working on a site where 90% of the admin area is handled via ajax / json.
So I am at the point where I login, destroy the session (on purpose) and try to perform an action, which obviously fails but how can I trigger it to force the user back to login page, your session has expired please login to continue message type setup?
I know about 'ajaxLogin' => '/Elements/users/ajax_login', which is what I used before altering all calls to be JSON so no HTML is now getting spit back to the view.
Just wondering what the easiest, site wide approach would be to direct a user to the login page if their session has expired when attempting an ajax request.
Any and all ideas welcome,
Thanks
Dave
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment