Iluvatar+ Posted February 29, 2012 Share Posted February 29, 2012 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] Quote Link to comment https://forums.phpfreaks.com/topic/257987-nfinite-loop-redirect-with-isauthorized-function/ Share on other sites More sharing options...
Iluvatar+ Posted March 1, 2012 Author Share Posted March 1, 2012 I have a isAuthorized function in cakephp and i need to be able to select some data and loop it with in the controller function. Is this possible, if so please share... Quote Link to comment https://forums.phpfreaks.com/topic/257987-nfinite-loop-redirect-with-isauthorized-function/#findComment-1322685 Share on other sites More sharing options...
thehippy Posted March 1, 2012 Share Posted March 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257987-nfinite-loop-redirect-with-isauthorized-function/#findComment-1322870 Share on other sites More sharing options...
jcombs_31 Posted March 4, 2012 Share Posted March 4, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257987-nfinite-loop-redirect-with-isauthorized-function/#findComment-1323893 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.