コード例 #1
0
ファイル: UsrController.php プロジェクト: rumatakira/yii2-usr
 /**
  * Sends out an email containing instructions and link to the email verification
  * or password recovery page, containing an activation key.
  * @param  \yii\base\Model $model it must have a getIdentity() method
  * @param  string     $mode  'recovery', 'verify' or 'oneTimePassword'
  * @return boolean    if sending the email succeeded
  */
 public function sendEmail(\yii\base\Model $model, $mode)
 {
     $params = ['siteUrl' => \yii\helpers\Url::toRoute(['/'], true)];
     switch ($mode) {
         default:
             return false;
         case 'recovery':
         case 'verify':
             $subject = $mode == 'recovery' ? Yii::t('usr', 'Password recovery') : Yii::t('usr', 'Email address verification');
             $params['actionUrl'] = \yii\helpers\Url::toRoute([$this->module->id . '/default/' . $mode, 'activationKey' => $model->getIdentity()->getActivationKey(), 'username' => $model->getIdentity()->username], true);
             break;
         case 'oneTimePassword':
             $subject = Yii::t('usr', 'One Time Password');
             $params['code'] = $model->getNewCode();
             break;
     }
     $message = Yii::$app->mailer->compose($mode, $params);
     $message->setTo([$model->getIdentity()->getEmail() => $model->getIdentity()->username]);
     $message->setSubject($subject);
     return $message->send();
 }