-1

yii では、パスワードを忘れる機能を作成しています。パスワードを忘れたボタンをクリックすると、サーバーはプライマリ電子メール ID を入力するための空白のテキスト フィールドを持つ 1 つの php ページを提供します。次に、コントローラーのメソッドでこの電子メール ID を取得する方法と、この電子メール ID がデータベースに存在するかどうかを確認する方法を説明します。私を助けてください...

4

1 に答える 1

1

これは、開始するのに役立ちます。これと同様のメソッドをコントローラーに配置し、パスワード フィールドを含むビューを作成します。

public function actionForgotPassword(){

  if(isset($_POST['email']{
    $record=User::model()->find(array(
      'select'=>'email',
      'condition'=>'email=:email',
      'params'=>array(':email'=>$_POST['email']))
    );

    if($record===null) {
      $error = 'Email invalid';
    } else {
      $newpassword = 'newrandomgeneratedpassword';
      $record->password = md5($newpassword );
      $record->save(); //you might have some issues with the user model when the password is protected for security
      //Email new password to user
    }
  }else{
    $this->render('forgetPassword'); //show the view with the password field
  }

}
于 2012-11-27T13:11:06.950 に答える