2

yii で、パスワードを忘れる機能を作成しています。このユーザーは、電子メール ID を入力します。この電子メール ID が正しい場合、データベースから securityQuestion ID を取得し、その質問をユーザーに表示します。答えが正しい場合、パスワード リセット リンクが送信されます。ユーザーの電子メールIDに。コントローラーで私は次のように行動しました

 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 = "abc@shailani.com";
          $mailer->Password = "abc";
          $mailer->From = "xyz@shailani.com";
          $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}}

プライマリメールIDと送信ボタンを入力するためのビューファイルとしてpassword.phpを持っています

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

ただし、ユーザーがプライマリ電子メール ID を送信した後、アクションは実行されません。だから誰か私がする必要がある変更を教えてください

4

2 に答える 2

0

OK、最初は気に入っています。上記の既存のコードに対する修正の一部を次に示します。

ただし、電子メールの送信に成功した後の計画は何でしたか。既存のコードを参照すると、http: //yoursite.com/yourapp/user/forgetのような URL が取得 され、メールを入力するフォームにすぐに戻るため、巨大なループが作成されます。

リンクが実際に作成され、検証され、ユーザーにユーザー レコードへのアクセス権が付与されることを確認してください。パスワードの変更を検証して許可するには、他の機能が必要です。

<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 = "yourgmailacccount@gmail.com";
              $mailer->Password = "P@ssWord";
              $mailer->From = "yourfromemail@yourdomain.com";
              $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!");
}

}

于 2013-09-17T21:31:56.097 に答える
0

actionForgotコントローラーメソッドの名前を の代わりにすべきではありませんActionForgot。PHP は大文字と小文字を区別します。また、ページをレンダリングするときに、モデル名のようthis->render->('emailForm',$email)にモデルを送信します$email

于 2013-01-19T15:39:45.493 に答える