2

I am facing problem to activate an user by click on activation link that sent by email.

After click on activation link i.e. http://www.example.com/devtest/index.php?r=user/check&activationcode=bc74873d0e3f684d3e6b99a36169a793ee688406 then it redirect to login page without updating database.

I think my following controller code not working for view file check.php which located on user directory. Here is my code-

UserController.php:

public function actionCheck(){$activationcode = Yii::app()->request->getQuery('activationcode');
if(isset($activationcode))
{
  $model = User::model()->findByAttributes(array('activationcode'=>$activationcode));

  if($model !== null)
  {            
    $model->status=1;
    $model->save();Yii::app()->user->setFlash('check','Thank you for register with us');
    $this->refresh();
  }
}

$this->render('check',array('model'=>$model));

}

View file check.php:

 <?php if(Yii::app()->user->hasFlash('check')): ?>
 <div class="flash-success">
   <?php echo Yii::app()->user->getFlash('check'); ?>
 </div>
<?php endif; ?>

I am not sure how I can handle GET URL action in UserController. Also, I already tested by adding word 'check' in accessRules but then browser show me Page not redirect properly.

public function accessRules()
    {
            return array(
                    array('allow',  // allow all users to perform 'index' and 'view' actions
                            'actions'=>array('index','create','view','captcha'),
                            'users'=>array('*'),
                    ),);}

Any idea? Please give me a solution about my issue.

With Thanks, MRS

3
  • I think my problem is in actionCheck function. When I click on activation link then in controller actionCheck function it can't handle GET URL correctly.
    – user1216487
    Sep 7, 2012 at 6:25
  • "redirect to login page without updating database" ... This happens if you user does not have permission to view the activation-URL. Why don't you remove filter() and accessRules() temporarily and see if you can access the activation-URL? You can also try adding 'devtest' to AccessRules. Sep 7, 2012 at 14:27
  • Then the following text show on browser "The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies."
    – user1216487
    Sep 8, 2012 at 4:53

2 Answers 2

0

I think that your model is null, so you can't update database.

Also I think that your action should be like this

public function actionCheck(){$activationcode = null){ 
if(!is_null($activationcode))
{
   $model = User::model()->findByAttributes(array('activationcode'=>$activationcode));

if($model){            
    $model->status=1;
    if($model->save())
       Yii::app()->user->setFlash('check','Thank you for register with us');
    $this->refresh();
}else{
  Yii::app()->user->setFlash('check','Something is wrong!');
}
}
    $this->render('check',array('model'=>$model));
}
0
0

I think you haven't added Check action to your accessControl and allowed all users to it. Could you please paste your accessRules array code here?

    public function filters() {
    return array(
            'accessControl', 
            );
}

public function accessRules() {
    return array(
        array('allow', // allow all users to perform 
            'actions'=>array('check'),
                'users'=>array('*'),
                ),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.