Jump to content
Larry Ullman's Book Forums
mrs

Facing Difficulties To Activate User Registration By Email

Recommended Posts

Hi All,

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

 

Here is my code-

UserController.php:

public function actionCreate()
{
$model=new User;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);

if(isset($_POST['User']))
{
 $model->attributes=$_POST['User'];
 $model->createtime=date('Y-m-d H:i:s');

 $model->activationcode = sha1(mt_rand(10000, 99999).time().$model->email);

 if($model->save())
 {
	 $to = $model->email;
	 $subject = "Welcome To My Site!"		
	 $message2 = "<html>
						 <body>Please click this below to activate your membership<br />".
							 Yii::app()->createAbsoluteUrl('user/check', array('activationcode' => $model->activationcode))."		
					 Thanks you

					 </body>
				 </html>";

	 $headers = 'MIME-Version: 1.0' . "\r\n";
	 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	 $headers .= 'From: My Site < admin@mysite.com>' . "\r\n";

	 mail($to,$subject,$message2,$headers);

	 $this->redirect(array('view','id'=>$model->id));
 }
}

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

 

public function actionCheck()
{
$activationcode = Yii::app()->request->getQuery('activationcode');
// collect user input data
if(isset($activationcode))
{

 $model = User::model()->find('activationcode=:activationcode', array(':activationcode'=>$activationcode));

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

}
// display the login form
$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 why activation link not working. After click on activation link then status not changed to 1 in database. Also, the page redirect to create view page. I was testing by adding 'check' in rules but then page stopped to redirect. I need quick help.

 

With thanks,

MRS

Share this post


Link to post
Share on other sites

Hi,

After click on activation link http://www.example.com/devtest/index.php?r=user/check&activationcode=bc74873d0e3f684d3e6b99a36169a793ee688406 then it redirect to login page. I think my following controller code not working for view file check.php which located on user directory.

public function actionCheck()
{
$model=new User;
$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,
		 ));
}

 

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 idea about how I can solve this.

 

With Thanks,

MRS

Share this post


Link to post
Share on other sites

First of all, read the forum guidelines before you ever post again. The fact that you need quick help does not make that my problem. I'm providing free help to strangers here and reply as I have time. Never forget that.

 

To debug this, I would start by confirming that the right controller method is being called. Then confirm that the activation code is accessible within that controller. Then confirm that the model is loaded.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...