Re: Problem with Auth. with an AJAX Request
well, i haven't done this specifically so I'm not sure I can demonstrate exactly how, but you probably either have to allow ('addToWatchlist') in your before filter then instead test if the request comes from a logged in user in that action before you add the link to the watch list. If it does NOT, you can serve up a login form in a popup window via AJAX, but you won't be redirected unless you do some kind of javascript XML or JSON test on the response. The reason you don't redirect is that if you let auth handle the 'behind the scenes' request, it will simply re-route the request to your default login redirect - probably the login page - which won't do anything at all since you aren't doing anything with the request. You should read up on AJAX. If you want to know how to serve up a login form with AJAX and submit it start with a basic AJAX tutorial and go from there? http://www.w3schools.com/Ajax/Default.Asp On May 20, 4:21 pm, Luke wrote: > Hi, > > I am not sure what else I could copy & paste from the sourcecode. I > only have a normal login action, in my user controller, which only > saves the last login and thats pretty much it. An Login AJAX action? > How would this look? > Have you got an example? > > Thanks. Luke > > On 20 Mai, 22:18, christo wrote: > > > all I can think of is that you don't have a login AJAX action set up > > so the request dies without redirecting to a log in if you try to > > access the link from not logged in? I dunno it's hard to tell from > > your description. pastebin maybe? > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with Auth. with an AJAX Request
Hi, I am not sure what else I could copy & paste from the sourcecode. I only have a normal login action, in my user controller, which only saves the last login and thats pretty much it. An Login AJAX action? How would this look? Have you got an example? Thanks. Luke On 20 Mai, 22:18, christo wrote: > all I can think of is that you don't have a login AJAX action set up > so the request dies without redirecting to a log in if you try to > access the link from not logged in? I dunno it's hard to tell from > your description. pastebin maybe? > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with Auth. with an AJAX Request
all I can think of is that you don't have a login AJAX action set up so the request dies without redirecting to a log in if you try to access the link from not logged in? I dunno it's hard to tell from your description. pastebin maybe? On May 20, 10:58 am, Luke wrote: > Hi, > > I have again read backwards and forwards through the www to find a > solution for my problem. I am sure that there is other people running > into the same issue. How do you guys solve it? > > All I want is a link saying "Add article to watchlist" which than, if > the User is logged in writes it into the DB, Article gets shown again > and link changes to "In watchlist" and if User is not logged in > redirects to the Login Window with a message that you need to be > logged in to use this feature. All this should happen with AJAX. My > normal login is happening with Auth. and the typical stuff in the > beforeFilter() of the app_controller. In the watchlist controller I > have added > > function beforeFilter() { > parent::beforeFilter(); > $this->Auth->deny('addToWatchlist'); > > } > > It should be very common and sometimesI think that maybe I am > searching for the wrong topic. Can anyone give me an advice? Thanks so > much. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with Auth. with an AJAX Request
Hi, I have again read backwards and forwards through the www to find a solution for my problem. I am sure that there is other people running into the same issue. How do you guys solve it? All I want is a link saying "Add article to watchlist" which than, if the User is logged in writes it into the DB, Article gets shown again and link changes to "In watchlist" and if User is not logged in redirects to the Login Window with a message that you need to be logged in to use this feature. All this should happen with AJAX. My normal login is happening with Auth. and the typical stuff in the beforeFilter() of the app_controller. In the watchlist controller I have added function beforeFilter() { parent::beforeFilter(); $this->Auth->deny('addToWatchlist'); } It should be very common and sometimesI think that maybe I am searching for the wrong topic. Can anyone give me an advice? Thanks so much. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with Auth. with an AJAX Request
Hi brian, thanks for your response. This is not really a solution I am looking for. I think the link should still be visible all the time and I can't imagine that cake and AJAX would not be able to handle this somehow. I am sure that someone has faced a similar issue before and I am hoping that they will share their solution. But thank you anyway. Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with Auth. with an AJAX Request
An AJAX request returns a chunk of HTML (or other data) and isn't going to handle the redirect properly. The simplest way to deal with this is to only display the link if the user is logged in. On Tue, May 19, 2009 at 8:36 AM, Luke wrote: > > Hi, > > I am still pretty new to CakePHP, so I am sorry if this is a silly > issue I am dealing with. Ok, I am working on a site where you have > different sections which require a Login. > > I therefore added the below Code into the app_controller > > var $components = array('Auth'); > var $helpers = array('Html','Form','Ajax','Javascript'); > > function beforeFilter() { > $this->Auth->loginAction = array('controller' => 'users', > 'action' => 'login'); > $this->Auth->logoutRedirect = array('controller' => 'users', > 'action' => 'login'); > $this->Auth->allow('*'); > $this->Auth->authorize = 'controller'; > $this->Auth->userScope = array('User.confirmed' => '1'); > $this->set('loggedIn', $this->Auth->user('id')); > $this->set('username', $this->Auth->user('username')); > } > > function isAuthorized() { > return true; > } > > So, all in all I allow all pages and than deny access to some > functions which are than directly in the controller. I thought that > this will be the easier way. > > I have now got a link to add a new article. In my controller I than > have added this part: > > function beforeFilter() { > parent::beforeFilter(); > $this->Auth->deny('add'); > } > > As I planned, if you are not logged in, the Login Window shows up and > only when you logged in, the Form to add an article will show up. > > So all this works and I thought I now go a step further. You can add > articles on your watchlist. Great, the article shows up, a link gets > displayed on top of it "Add article to watchlist" this time I want to > use an AJAX request. > > So I created the AJAX link > > echo $ajax->link(Add article to watchlist', > array('controller' => mylist, 'action' =>'add', $articledetail > ['Article']['id']), > array('update' => 'message', > )); > > and added the below in my watchlist_controller > > function beforeFilter() { > parent::beforeFilter(); > $this->Auth->deny('add'); > } > > So, what happens now? When you are not logged in, the article does not > get add to your watchlist, but the Login Window does not show up. > Instead you just still see the article not knowing if anything > happened in the background. > > Of course I would like the Login Window to show up and when you are > logged in the Article should be added to your watchlist, the article > should show up again and the link should change to "Article in > watchlist". > > Why is this not working with AJAX Link and how to I get it to work? I > have read through the www, but can't find an answer. Maybe I am > looking for the wrong topic... Can anyone here help? > > Look forward to some response. Thanks so much in advance. > > Luke > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Problem with Auth. with an AJAX Request
Hi, I am still pretty new to CakePHP, so I am sorry if this is a silly issue I am dealing with. Ok, I am working on a site where you have different sections which require a Login. I therefore added the below Code into the app_controller var $components = array('Auth'); var $helpers = array('Html','Form','Ajax','Javascript'); function beforeFilter() { $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); $this->Auth->allow('*'); $this->Auth->authorize = 'controller'; $this->Auth->userScope = array('User.confirmed' => '1'); $this->set('loggedIn', $this->Auth->user('id')); $this->set('username', $this->Auth->user('username')); } function isAuthorized() { return true; } So, all in all I allow all pages and than deny access to some functions which are than directly in the controller. I thought that this will be the easier way. I have now got a link to add a new article. In my controller I than have added this part: function beforeFilter() { parent::beforeFilter(); $this->Auth->deny('add'); } As I planned, if you are not logged in, the Login Window shows up and only when you logged in, the Form to add an article will show up. So all this works and I thought I now go a step further. You can add articles on your watchlist. Great, the article shows up, a link gets displayed on top of it "Add article to watchlist" this time I want to use an AJAX request. So I created the AJAX link echo $ajax->link(Add article to watchlist', array('controller' => mylist, 'action' =>'add', $articledetail ['Article']['id']), array('update' => 'message', )); and added the below in my watchlist_controller function beforeFilter() { parent::beforeFilter(); $this->Auth->deny('add'); } So, what happens now? When you are not logged in, the article does not get add to your watchlist, but the Login Window does not show up. Instead you just still see the article not knowing if anything happened in the background. Of course I would like the Login Window to show up and when you are logged in the Article should be added to your watchlist, the article should show up again and the link should change to "Article in watchlist". Why is this not working with AJAX Link and how to I get it to work? I have read through the www, but can't find an answer. Maybe I am looking for the wrong topic... Can anyone here help? Look forward to some response. Thanks so much in advance. Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---