예제 #1
0
 /**
  * Creates new confirmation token and sends it to the user.
  *
  * @return bool
  */
 public function resend()
 {
     if (!$this->validate()) {
         return false;
     }
     /** @var Token $token */
     $token = Yii::createObject(['class' => Token::className(), 'userId' => $this->user->id, 'type' => Token::TYPE_CONFIRMATION]);
     $token->save(false);
     $this->mailer->sendConfirmationMessage($this->user, $token);
     Yii::$app->session->setFlash('info', Yii::t('users', 'A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.'));
     return true;
 }
예제 #2
0
 /**
  * Sends recovery message.
  *
  * @return bool
  */
 public function sendRecoveryMessage()
 {
     if ($this->validate()) {
         /** @var Token $token */
         $token = Yii::createObject(['class' => Token::className(), 'userId' => $this->user->id, 'type' => Token::TYPE_RECOVERY]);
         if (!$token->save(false)) {
             return false;
         }
         if (!$this->mailer->sendRecoveryMessage($this->user, $token)) {
             return false;
         }
         Yii::$app->session->setFlash('info', Yii::t('users', 'An email has been sent with instructions for resetting your password'));
         return true;
     }
     return false;
 }
예제 #3
0
파일: User.php 프로젝트: yujin1st/yii2-user
 /**
  * This method is used to register new user account. If Module::enableConfirmation is set true, this method
  * will generate new confirmation token and use mailer to send it to the user.
  *
  * @return bool
  */
 public function register()
 {
     if ($this->getIsNewRecord() == false) {
         throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
     }
     $this->confirmTime = $this->module->enableConfirmation ? null : time();
     $this->password = $this->module->enableGeneratingPassword ? Password::generate(8) : $this->password;
     $this->trigger(self::BEFORE_REGISTER);
     if (!$this->save()) {
         return false;
     }
     if ($this->module->enableConfirmation) {
         /** @var Token $token */
         $token = Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]);
         $token->link('user', $this);
     }
     if ($this->email) {
         $this->mailer->sendWelcomeMessage($this, isset($token) ? $token : null);
     }
     $this->trigger(self::AFTER_REGISTER);
     return true;
 }
예제 #4
0
 /**
  * Sends a confirmation message to both old and new email addresses with link to confirm changing of email.
  *
  * @throws \yii\base\InvalidConfigException
  */
 protected function secureEmailChange()
 {
     $this->defaultEmailChange();
     /** @var Token $token */
     $token = Yii::createObject(['class' => Token::className(), 'userId' => $this->user->id, 'type' => Token::TYPE_CONFIRM_OLD_EMAIL]);
     $token->save(false);
     $this->mailer->sendReconfirmationMessage($this->user, $token);
     // unset flags if they exist
     $this->user->flags &= ~User::NEW_EMAIL_CONFIRMED;
     $this->user->flags &= ~User::OLD_EMAIL_CONFIRMED;
     $this->user->save(false);
     Yii::$app->session->setFlash('info', Yii::t('users', 'We have sent confirmation links to both old and new email addresses. You must click both links to complete your request'));
 }