1

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

Give me solution for these two process.

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

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

Code in Controller

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

}

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

        ),
    ),
8
  • you know, it's a conventional process in all modern websites, that verifying a new user by he's email. Commented Jul 6, 2013 at 12:53
  • have you written the code to send the email or you want the entire solution ?? Commented Jul 6, 2013 at 12:59
  • 1
    Hi and welcome to StackOverflow. This site is not one where people "give you a solution"; you need to demonstrate trying to solve and having trouble with a specific problem. You are most likely not going to get an answer because of that. Please take the tour and read the FAQ on asking questions. Commented Jul 6, 2013 at 12:59
  • Hi, thanks for your suggestion, now i updated my question with code Commented Jul 6, 2013 at 13:03
  • What problem are u facing ?? Commented Jul 6, 2013 at 13:04

1 Answer 1

0

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

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. ";
        }
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Ninad, for your quick responds, let me try this
Ninad, this is my url structure in this which pat is the key and what i have to replace with your variable (key) localhost/launch/SignUp/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.