/** * 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->confirmed_at = $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); } $this->mailer->sendWelcomeMessage($this, isset($token) ? $token : null); $this->trigger(self::AFTER_REGISTER); return true; }