Jump to content

nfinite loop redirect with isAuthorized function


Recommended Posts

Now this is driving me up the wall, as i cant see were i am going wrong. I am trying to set up a role permision in the isAuthorized function, i have got it working in regards to allowed pages, but any page that isn't allowed when a i try and gain unauthorized access it it is get stuck in a infinite loop redirect rather than just redirecting to the previous or login action. If any one can help me on this i would be a happy chap!

 

Here is my code (both beging in the app controller)

<?php
function beforeFilter() {
            parent::beforeFilter();
            $user = $this->Auth->user();
  			$this->set(compact('user'));
            $this->Auth->loginRedirect = array('controller' => 'User', 'action' => 'Registers');
            $this->Auth->allow('Users');
            $this->Auth->authorize = 'controller';
            $this->Auth->loginError = "Error";					  
            $this->Auth-> authError  = "Error";
                                      
    }
    
    
    function isAuthorized() {
         $this->Auth->autoRedirect = false; 
        
         if($this->action=='stepone' || $this->action=='steptwo') {
             //$current_user_role = $session->read('Auth.User.role');
             if($this->Auth->user('role') == 'user') {
         		return true;
             }
             else{
                 //Redirect to error notification page
                 $this->Session->setFlash('Sorry, you don\'t have permission to access that page.');
                 $this->redirect('login');
                 return false;
             }
         }
         parent::isAuthorized ();
        
        
    }
?>

In the another controller
[code]
function beforeFilter() {
     	parent::beforeFilter(); 
     	$this->Auth->deny('*'); //Disallow access to all actions
}

[/code]

I assume given the new topic in this subforum titled 'Cakephp using a foreach loop in a controller function', that these are related issues and that your problem in this topic is a Cake problem which you neglected to mention.  Do not double post, simply update/reply to the topic with what you have tried that has not worked for you, it is helpful and courteous to those who wish to help you solve your problem.

 

If you are getting an infinite redirect loop, look at your code where you are redirecting.  Under what condition will you redirect?  What happens when you redirect?  If for instance the conditions that trigger a redirect are met again by your redirect, weeeeee happy infinite loop time.

You have a Auth->deny on everything and also calling parent::isAuthorized which gives no indication of what is in parent or why you'd want to do this.  Not sure why you are over complicating things. Just use the examples the cookbook gives you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.