sendEmailConfirmation() public method

Send email confirmation to user
public sendEmailConfirmation ( amnah\yii2\user\models\UserToken $userToken ) : integer
$userToken amnah\yii2\user\models\UserToken
return integer
Ejemplo n.º 1
0
 /**
  * Process data after registration
  * @param \amnah\yii2\user\models\User $user
  */
 protected function afterRegister($user)
 {
     /** @var \amnah\yii2\user\models\UserToken $userToken */
     $userToken = $this->module->model("UserToken");
     // determine userToken type to see if we need to send email
     $userTokenType = null;
     if ($user->status == $user::STATUS_INACTIVE) {
         $userTokenType = $userToken::TYPE_EMAIL_ACTIVATE;
     } elseif ($user->status == $user::STATUS_UNCONFIRMED_EMAIL) {
         $userTokenType = $userToken::TYPE_EMAIL_CHANGE;
     }
     // check if we have a userToken type to process, or just log user in directly
     if ($userTokenType) {
         $userToken = $userToken::generate($user->id, $userTokenType);
         if (!($numSent = $user->sendEmailConfirmation($userToken))) {
             // handle email error
             //Yii::$app->session->setFlash("Email-error", "Failed to send email");
         }
     } else {
         Yii::$app->user->login($user, $this->module->loginDuration);
     }
 }
Ejemplo n.º 2
0
 /**
  * Process data after registration
  *
  * @param \amnah\yii2\user\models\User $user
  */
 protected function afterRegister($user)
 {
     /** @var \amnah\yii2\user\models\UserKey $userKey */
     // determine userKey type to see if we need to send email
     $userKey = Yii::$app->getModule("user")->model("UserKey");
     if ($user->status == $user::STATUS_INACTIVE) {
         $userKeyType = $userKey::TYPE_EMAIL_ACTIVATE;
     } elseif ($user->status == $user::STATUS_UNCONFIRMED_EMAIL) {
         $userKeyType = $userKey::TYPE_EMAIL_CHANGE;
     } else {
         $userKeyType = null;
     }
     // check if we have a userKey type to process, or just log user in directly
     if ($userKeyType) {
         // generate userKey and send email
         $userKey = $userKey::generate($user->id, $userKeyType);
         //send email to admin
         $user->sendEmailWhenRegistered($userKey);
         if (!($numSent = $user->sendEmailConfirmation($userKey))) {
             // handle email error
             //Yii::$app->session->setFlash("Email-error", "Failed to send email");
         }
     } else {
         Yii::$app->user->login($user, Yii::$app->getModule("user")->loginDuration);
     }
 }