我的问题是从电子邮件代码激活帐户。当前功能发送电子邮件代码但未激活登录(创建没有点击验证链接的新用户)。
这是我的控制器代码 -
public function actionSignup()
{
$model=new User;
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
$image=CUploadedFile::getInstance($model,'image');
if($image!=NULL)
{
$model->image = $image;
$image->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$image);
}
$model->registration_date = date("Y-m-d H:i:s");
$model->user_status= 'Disabled';
$activation_code= mt_rand(0x000000, 0xffffff);
$model->activation_code=$activation_code;
if($model->save())
{
$to =$_POST['User']['email'];
$User=User::model()->find(
'"email"=:email', array(':email'=>$to)
);
$subject = "Activate your account on www.polymyositisresearch.org";
$subject='=?UTF-8?B?'.base64_encode($subject).'?=';
echo $comment =
"<html>
<body>
\r\nPlease<a href=".Yii::app()->createAbsoluteUrl("user/signup-confirmation",
array("secure_activation_key"=>$activation_code))." > Click here </a> to activate your account.
\r\nThank you.
</body>
</html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From: www.polymyositisresearch.org< admin@polymyositisresearch.org>' . "\r\n";
if(mail($to,$subject,$comment,$headers))
{
Yii::app()->user->setFlash('success','An activation email has sent to your email address.
Please activate your account and continue to next step on polymyositisresearch.org. Thank you.');
$this->refresh();
}
else
echo "SMTP Server Error";
}
else
{
$model->password = ''; // if the validate failed, clear out the password before re-rendering the form
$model->verifyPassword = '';
}
}
$this->render('sign-up',array('user'=>$model));
}
激活功能 -
public function actionSignupconfirmation($secure_activation_key)
{
$User=User::model()->find(
'activation_code=:activation_code', array(':activation_code'=>$secure_activation_key)
);
if($User!=NULL)
{
if($User->activation_code==$secure_activation_key)
{
$activate_code= mt_rand(0x000000, 0xffffff);
$User->activation_code=$activate_code;
$User->user_status= 'Enabled';
$User->save(false);
Yii::app()->user->setFlash('success','Congrats! Your account has been verified successfully. Please login to access your account. Thank you.');
}
}
else
{
Yii::app()->user->setFlash('error','Account confirmation unsuccessful. Please try again.');
//$this->refresh();
}
$this->render('signup-confirmation');
}
非常感谢一点帮助。点击验证邮件后我需要一些指导,然后创建新用户。