Accessrules

Hi Everyone,

I have been wrestling with the accessRules in my SiteController. I want to set rules for accessing the second registration page (site/signUpNext) in my sign up registration process. I only want to allow access if they are coming from the first registration page (site/signUp) and they are not signed in (obviously). Here is my accessRules code snippet for my second registration page:




 array('allow', 

   'actions'=>array('signUpNext'),

   'expression'=> '$user->isGuest  && ($user->returnUrl == "site/signUp")',

 ),  



I also put this next code snippet in my signUp action…




Yii::app()->user->setReturnUrl('site/signUp');



Any help with this is very much appreciated! Thanks!

How about using setState:




Yii::app()->user->setState('allowSignUpNext', true);



then use getState in the expression:




'expression' => '$user->isGuest  && $user->getState("allowSignUpNext", false)',



Thanks explorer for your help! I was having problems with the way I had it set up. This is working…




        protected function beforeAction($action) {

            if (parent::beforeAction($action)){


                if($this->action->id == 'signUp') {  

                    Yii::app()->user->setState('allowSignUpNext', true);

                }else{

                    Yii::app()->user->setState('allowSignUpNext', false);

                }


                return true; // this line is important to let the action continue

            }

            return false;

        } 



This code along with your expression suggestion in the accessRules.

Again, many thanks to you!

That looks to work at first, but I find that it works sparingly. It is hitting before action twice and the second time it get an error on the close() function in CHttpSession.php:




	public function close()

	{

		if(session_id()!=='')

			@session_write_close();

	}




This is causing my states to get reset, so I am now again searching for a new solution.

I have no idea with the error in CHttpSession, but if you write the code in beforeAction like that, I think it will be executed before actionSignUpNext as well and allowSignUpNext will be set as false. Maybe you can put the setState code in actionSignUp (after user submitted the 1st sign up form)?

Yes, you are correct. Putting it in after the submission works. I also had to set it back to false within the SignUpNext action. It is working great now. Thanks so much for your help!! :slight_smile: