yii框架中的电子邮件验证 [英] Email Verification in yii framework

查看:145
本文介绍了yii框架中的电子邮件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to verify the user when he click the random generated URL.

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

Give me solution for these two process.

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

1.What is the URL manager configuration rules for get the hash (string and numbers) from url request?

2.如何在Controller/Action上将URL中的哈希值与数据库中的哈希值进行比较?

2.How can I compare the hash value in URL with my hash value in database on Controller/Action?

用于发送电子邮件的代码(可以正常工作)

Code for sending email (it's working fine)

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配置

and current URLManager configuration

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

        ),
    ),

推荐答案

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

Make change in your Url manager as shown

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

和样品确认动作 以get参数的形式发送电子邮件,并在url中输入密钥,并像我在密码

And the sample confirm action Send the email in the format of get parameters with the key in the url and get that key in action as i have done in passkey

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. ";
        }
    }

这篇关于yii框架中的电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆