コード例 #1
0
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $admin Admin */
     $admin = Admin::findOne(['email' => $this->email]);
     if ($admin) {
         if (!Admin::isPasswordResetTokenValid($admin->pwd_reset_token)) {
             $admin->generatePasswordResetToken();
         }
         if ($admin->save()) {
             return \Yii::$app->mailer->compose(['html' => 'admin/password_reset.html.php', 'text' => 'admin/password_reset.txt.php'], ['user' => $admin])->setFrom([Yii::$app->params['from.email'] => Yii::$app->params['from.name']])->setTo($this->email)->setSubject(Yii::t('admin', 'Password reset for {appName}'), ['appName' => Yii::$app->name])->send();
         }
     }
     return false;
 }
コード例 #2
0
 /**
  * Finds the Admin model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Admin the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Admin::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }