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 <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to