2012-11-28 35 views
2

在yii我創建忘記密碼功能。爲此用戶輸入電子郵件id.If此電子郵件ID是正確的,然後我想從數據庫中檢索securityQuestion ID並顯示該問題user.if他的回答是正確的,然後密碼重置鏈接將發送到用戶的電子郵件ID。在控制器我做了行動在yii如何發送密碼重置鏈接

public function ActionForget{if(isset($_POST['email'])) 
     { $record=User::model()->find(array(
     'select'=>'primaryEmail', 
     'condition'=>'PrimaryEmail=:email', 
     'params'=>array(':email'=>$_POST['email'])) 
      ); if($record===null) { 
     $error = 'Email invalid'; 
     } else { 
      $mailer = Yii::createComponent('application.extensions.mailer.EMailer'); 
      $mailer->IsSMTP(); 
      $mailer->IsHTML(true); 
      $mailer->SMTPAuth = true; 
      $mailer->SMTPSecure = "ssl"; 
      $mailer->Host = "smtp.gmail.com"; 
      $mailer->Port = 465; 
      $mailer->CharSet = 'UTF-8'; 
      $mailer->Username = "[email protected]"; 
      $mailer->Password = "abc"; 
      $mailer->From = "[email protected]"; 
      $mailer->FromName = "Balaee.com"; 
      $mailer->AddAddress($record); 
      $mailer->Subject = "welcome to Balaee"; 
      $mailer->IsHTML(true); 
      $mailer->Body = "<h1>Thanks to showing interest </h1><br>click on link for       other detail ".$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
if($mailer->Send()) {echo "Please check mail";} 
else {echo "Fail to send your message!"; }}} 
else{ $this->render('emailForm'); //show the view with the password field}} 

我有password.php作爲視圖文件進入主電子郵件ID和提交按鈕

 <?php $form=$this->beginWidget('CActiveForm', array(
     'id'=>'email-form', 
      'enableClientValidation'=>true, 
      )); 
      echo CHtml::textField('email'); 
      echo CHtml::submitButton('Send'); 
      $this->endWidget(); 

但用戶submiiting主電子郵件ID之後,沒有任何動作,地點。所以可以請別人告訴我我需要做什麼更改

+1

請通過將echo語句調試代碼,並檢查其中控制休息,然後發現問題。 – Hemc

+0

我現在正在逐步進行。如果電子郵件ID正確的,那麼我想從用戶表retrive該用戶的securityQuestionid以顯示安全問題他。我創造了查詢AS-如果(isset($ _ POST [「郵件」])){ $記錄=用戶1: :模型() - >查找(陣列( '選擇'=> 'primaryEmail', '狀態'=> 'primaryEmail =:電子郵件', 'PARAMS'=>數組( ':電子郵件'=> $ _ POST [ 'email'])));如果(!$ record === null) {echo「email exists」; $ ID =用戶1 ::模型() - > findByAttributes(陣列( '用戶id'=> $ record->用戶id)); $ SQID =用戶1 ::模型() - > findByAttributes(陣列( 'securityQuestionId'=> $ record-> securityQusetionId)); echo $ sqid;}} bt不工作 –

+0

一次又一次地發佈不會幫助你,試着寫一些代碼。謝謝。 –

回答

0

不應該控制器方法的名稱是actionForgot而不是ActionForgot。 PHP是區分大小寫的,當你渲染頁面發送模型像它this->render->('emailForm',$email)其中$email是你的型號名稱

+0

PHP是不區分大小寫。 – diesonne

0

好吧,我喜歡的開始,這裏是一些上述現有代碼的修復。

但是,一旦您成功發送電子郵件,您的計劃是什麼?看到現有的代碼會爲您提供一個看起來像這樣的網址http://yoursite.com/yourapp/user/forget,這會讓您回到您輸入電子郵件的形式,從而創建一個巨大的循環。

查看鏈接應實際上創建驗證,從而使用戶訪問其用戶記錄。您需要一些其他功能來驗證並允許更改密碼。

<code> 

public function actionForget() { 
     if(isset($_POST['email'])) { 
     $record=User::model()->findByAttributes(array('email' => Yii::app()->request->getPost('email'))); 
     if ($record != NULL) { 
       $mailer = Yii::createComponent('application.extensions.mailer.EMailer'); 
       $mailer->IsSMTP(); 
       $mailer->IsHTML(true); 
       $mailer->SMTPAuth = true; 
       $mailer->SMTPSecure = "ssl"; 
       $mailer->Host = "smtp.gmail.com"; 
       $mailer->Port = 465; 
       $mailer->CharSet = 'UTF-8'; 
       $mailer->Username = "[email protected]"; 
       $mailer->Password = "[email protected]"; 
       $mailer->From = "[email protected]"; 
       $mailer->FromName = "HQ-DEV-01"; 
       $mailer->AddAddress($_POST['email']); 
       $mailer->Subject = "welcome to CES Document Site"; 
       $mailer->IsHTML(true); 
       $mailer->Body = "<h1>Thanks, please</h1><br> 
          click on link for other detail 
          ".$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 

          if($mailer->Send()) { 
        echo "Please check your email"; 
       } 
       else { 
        echo "Fail to send your message!"; 
       } 

     } else { 
      echo 'Email invalid'; 
    } 
     else { 
     $this->render('password'); 
     Yii::app()->user->setFlash('error', "Email is not valid!"); 
     //echo 'Email invalid'; 
    } 

    } 
else{ $this->render('password'); //show the view with the password field}} 
     Yii::app()->user->setFlash('info', "Enter a valid e-mail!"); 
} 

}