【发布时间】:2013-07-04 09:25:17
【问题描述】:
我想在用户单击随机生成的 URL 时对其进行验证。
给我这两个过程的解决方案。
1.从url请求中获取hash(字符串和数字)的url manager配置规则是什么?
2.如何比较URL中的hash值和我在Controller/Action上数据库中的hash值?
发送电子邮件的代码(它工作正常)
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>',
),
),
【问题讨论】:
-
你知道,这是所有现代网站的常规流程,通过电子邮件验证新用户。
-
您是否编写了发送电子邮件的代码或者您想要整个解决方案??
-
您好,欢迎来到 StackOverflow。这个网站不是人们“给你解决方案”的地方;您需要证明尝试解决特定问题并遇到麻烦。因此,您很可能不会得到答案。请take the tour 并阅读FAQ on asking questions。
-
嗨,谢谢你的建议,现在我用代码更新了我的问题
-
你面临什么问题??
标签: php yii email-verification yii-url-manager