我想在用户点击随机生成的网址时验证用户 .
给我这两个过程的解决方案 .
1.从URL请求获取哈希(字符串和数字)的URL管理器配置规则是什么?
2.如何将URL中的哈希值与Controller / Action中数据库中的哈希值进行比较?
发送电子邮件的代码(工作正常)
protected function afterSave()
{
$activation_url = Yii::app()->createAbsoluteUrl('SignUp/Activate',array('activate_link'=>$this->activate_link));
Yii::import('ext.yii-mail.YiiMailMessage');
$message = new YiiMailMessage;
$message->setBody($activation_url);
$message->subject = 'Hello hell';
$message->addTo($this->email);
$message->from = Yii::app()->params['adminEmail'];
Yii::app()->mail->send($message);
return true;
}
控制器代码
public function actionActivate($activation) {
$model= Signup::model()->findByAttributes(array(
'activate_link' => $activation
));
if ($model === null)
$this->redirect('index.php');
else
$model->user_status = 1;
$model->save();
$this->redirect('index.php');
//redirect / flash / login whatever
}
和当前的URLManager配置
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
1 回答
如图所示,在您的Url管理器中进行更改
示例确认操作使用url中的密钥以get参数的格式发送电子邮件,并按照我在passkey中的操作获取该密钥