Tuesday, December 6, 2011

Re: ACL + Auth = Headache

Ok so it seems that this might be the culprit:

$this->Auth->authorize = 'actions';


If I comment out that line I dont get the redirect loop.

On Dec 6, 11:21 am, RhythmicDevil <rhythmicde...@gmail.com> wrote:
> I followed the instructions here:http://book.cakephp.org/view/1543/Simple-Acl-controlled-Application
> to learn how to setup ACL and Auth. My two test attempts went smoothly
> and worked as expected. However, now that I am trying it for real its
> failing. I get stuck in this redirect loop and I dont understand why.
> No matter what valid URL I enter, I get a redirect loop.
>
> This is the beforeFilter in my AppController:
>
>     function beforeFilter()
>     {
>         parent::beforeFilter();
>
>         //$this->Auth->allow(array('*'));
>
>         //Configure AuthComponent
>         $this->Auth->authorize = 'actions';
>         /*
>          * If the user did not select a controller/action before
> logging in, then
>          * this controller/action willbe executed.
>          */
>         $this->Auth->loginAction = array('controller' => 'users',
> 'action' => 'login');
>         /*
>          * Send the user here after logging out
>          */
>         $this->Auth->logoutRedirect = array('controller' => 'users',
> 'action' => 'login');
>         /*
>          * Send the user here after logging in.
>          */
>         $this->Auth->loginRedirect = array('controller' => 'main',
> 'action' => 'index');
>     }
>
> Here are the login() and logout() methods for my users_controller
>
>     function login()
>     {
>         if ($this->Session->read('Auth.User'))
>         {
>
>             $this->Session->setFlash('You are logged in!');
>             $this->redirect($this->Auth->loginRedirect, null, false);
>         }
>     }
>
>     function logout()
>     {
>
>         exit('WTF');
>
>         $this->Session->setFlash('Good-Bye');
>         $this->redirect($this->Auth->logout());
>     }
>
> I expect if I enter:http://swright-dev.epic-cake/users/logoutI would
> see "WTF" on the screen. I get redirected.
>
> This is what I see repeated in my Apache access_log:
> 172.27.3.23 - - [06/Dec/2011:11:12:58 -0500] "GET / HTTP/1.1" 302 1
> "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101
> Firefox/5.0"
>
> Nothing is generated in the Apache error_log, or Cake's error and
> debug logs.
>
> The only way the redirect loop stops is if I uncomment this line in
> the beforeFilter:
> //$this->Auth->allow(array('*'));
> But then no Auth works obviously. Can someone please point me in the
> right direction?
>
> Thanks.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: