1

我想在用户单击随机生成的 URL 时对其进行验证。

给我这两个过程的解决方案。

1.从url请求中获取hash(字符串和数字)的url管理器配置规则是什么?

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>',

        ),
    ),
4

1 回答 1

0

如图所示在您的网址管理器中进行更改

'urlManager'=>array(
//HK_DEVELOPER NR:CHANGED TO GET TO GET THE URL IN DESIRED FORMAT
    'urlFormat'=>'get',
    'rules'=>array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
),

示例确认操作以获取参数的格式发送电子邮件,其中包含 url 中的密钥,并像我在密码中所做的那样获取该密钥

public function actionConfirm(){
        //HK_DEVELOPER_NR:This action will confirm the user and change status from not authorize to authorized
        $passkey=$_GET['key'];
        $details=User::model()->findByAttributes(array('confirmationCode'=>$passkey));
        if(count($details)>=1)
        {
            if($details['userStatusId']==2){
                //CHECK IF AUTHORIZED REDIRECT TO PROFILE VIEW
                $url=Yii::app()->createUrl('site/login&joinbdp=false');
                $this->redirect($url);//USER CLICKS ON THE REGISTERATION LINK TWICE
            }else{
                $register=new Registerationconf;
                $value=$details['userId'];
                $register->userId=$value;
                $register->IPAddress=Yii::app()->request->userHostAddress;
                $register->confirmationTime=new CDbExpression('NOW()');
                $register->save();
                //CHANGE STATUS FROM NOT AUTHORIZED TO AUTHORIZED
                $post=User::model()->updateAll(array('userStatusId'=>'2'), 'confirmationCode=:confirmationCode',array(':confirmationCode'=>$passkey));
                $this->render('sucess');
            }
        }else {
            //IF USER IS REMOVED AND TRIES TO ACTIVATE THE LINK AGAIN
            echo "Please use valid URL. ";
        }
    }
于 2013-07-06T13:11:23.927 回答