Sends an email to a user with recovery link.

@param User  $user
@param Token $token

@return bool
161505
public function sendRecoveryMessage($user, $token)
    {
        $mailVars = [
            '{token}' => $token->url
        ];

        /**
         * @var $mailTemplate Template
         */
        $mailTemplate = \Yii::$app->get('emailTemplates')
            ->getTemplate('recovery', Language::getCurrent()->id);
        $mailTemplate->parseSubject($mailVars);
        $mailTemplate->parseBody($mailVars);

        return \Yii::$app->shopMailer->compose('mail-body', ['bodyContent' => $mailTemplate->getBody()])
            ->setFrom([\Yii::$app->shopMailer->transport->getUsername() => \Yii::$app->name ?? Url::to(['/'], true)])
            ->setTo($user->email)
            ->setSubject($mailTemplate->getSubject())
            ->send();
    }
772207
public function sendWelcomeMessage(User $user, Token $token = null)
    {
        $mailVars = [
            '{token}' => $token->url,
            '{legal_link}' => Url::toRoute([
                '/legal/default/view',
                'legalId' => Legal::findOne(['key' => 'buyers'])->id,
                'langId' => Language::getCurrent()->id
            ], true)
        ];

        /**
         * @var $mailTemplate Template
         */
        $mailTemplate = \Yii::$app->get('emailTemplates')
            ->getTemplate('welcome', Language::getCurrent()->id);
        $mailTemplate->parseSubject($mailVars);
        $mailTemplate->parseBody($mailVars);

        return \Yii::$app->shopMailer->compose('mail-body', ['bodyContent' => $mailTemplate->getBody()])
            ->setFrom([\Yii::$app->shopMailer->transport->getUsername() => \Yii::$app->name ?? Url::to(['/'], true)])
            ->setTo($user->email)
            ->setSubject($mailTemplate->getSubject())
            ->send();
    }
519724
protected function invalidateTwoFactorBackup(AuthenticatableTwoFactorContract $user, int $token): void
    {
        $settings = $user->getTwoFactor();
        $backup = array_get($settings, 'totp.backup');

        unset($backup[array_search($token, $backup)]);

        array_set($settings, 'totp.backup', $backup);

        // Update TwoFactor OTP backup codes
        $user->fill(['two_factor' => $settings])->forceSave();
    }
187975
public function verify(CanVerifyEmailContract $user, $token)
    {
        // If the responses from the validate method is not a user instance, we will
        // assume that it is a redirect and simply return it from this method and
        // the user is properly redirected having an error message on the post.
        $user = $this->validateVerification($user, $token);

        if (! $user instanceof CanVerifyEmailContract) {
            return $user;
        }

        $this->tokens->delete($token);

        $user->setVerified(true);

        $user->save();

        return VerifyEmailBrokerContract::EMAIL_VERIFIED;
    }
1357245
public function putBlock($user, $target, $token = null)
    {
        return $this->sendRequest('PUT', 'users/'.$user.'/blocks/'.$target, $this->getToken($token));
    }
371607
public function sendActivationMail($user)
    {
        if( ! $this->shouldSend($user) ) {
            return trans('HCACL::users.activation.check_email');
        }

        \DB::beginTransaction();

        try {
            $token = $this->createActivation($user);

            $user->sendActivationLinkNotification($token);
        } catch ( \Exception $e ) {
            \DB::rollback();

            throw new \Exception('Activation code or mail sending failed');
        }

        \DB::commit();

        return trans('HCACL::users.activation.resent_activation');
    }
803372
public function createTokenRequest(User $user, $issuer)
    {
        $idAttribution = $user->getCurrentAttribution() ? $user->getCurrentAttribution()->getId() : null;

        return (new TokenRequest())
            ->setUsername($user->getUserName())
            ->setAttributionId($idAttribution)
            ->setIssuer($issuer);
    }
113435
public function createResetEmailToken(User $user, $email)
    {
        return $this->create($user, self::TYPE_EMAIL_RESET, new \DateTime('+1 day'), $email);
    }
632882
public function setToken(UserSession $user, Token $token)
    {
        $item = $this->cacheItemPool->getItem($this->cacheKey($user));
        $item->set($token);
        // @todo Test that these values are compatible.
        $item->expiresAfter($token->getLifetime());
        $this->cacheItemPool->save($item);
    }
1053741
public function exists(CanVerifyEmailContract $user, $token)
    {
        $email = $user->getEmailToVerify();

        $token = (array) $this->getTable()->where('email', $email)->where('token', $token)->first();

        return $token && ! $this->tokenExpired($token);
    }
913830
public function userSubscriptionChannel($user, $channel, $token = null)
    {
        $token = $this->getToken($token);

        $subscriptionsAPI = new Subscriptions($token);

        return $subscriptionsAPI->userSubscriptionChannel($user, $channel);
    }
360327
protected function sendResetPasswordMessage($myWords, $name, $user, $email, $token)
	{
		$path = $this->_context->get("SCRIPT_NAME");
		$path = substr($path,0,strrpos($path,"/")+1);
		$url = "http://" . $this->_context->getServerName() . $path;
		$body = $myWords->ValueArgs("RESETPASSWORDMESSAGE", array($name, $this->_context->get("SERVER_NAME"), $user, $url.$this->_context->bindModuleUrl(str_replace('\\', '.', get_class()) . '?action=' . ModuleActionLogin::RESETPASSWORD . '&username=' . $user . '&resettoken=' . $token . '&returnurl=' . $this->_login->getReturnUrl())));

		$envelope = new MailEnvelope(
			Util::getFullEmail($email, $name),
			$myWords->Value("RESETSUBJECTMESSAGE", "[" . $this->_context->getServerName() . "]"),
			$body
		);
		$envelope->Send();
	}
579161
public function sendCreationEmailMessage(UserInterface $user, $password)
    {
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $siteName  = $this->settingsManager->getParameter('general.site_name');
        $userName = sprintf('%s %s', $user->getFirstName(), $user->getLastName());
        $login = $user->getUsername();

        if (0 === strlen($password)) {
            return 0;
        }

        if (null === $loginUrl = $this->getLoginUrl($user)) {
            return 0;
        }

        $rendered = $this->templating->render(
            'EkynaUserBundle:Admin/User:creation_email.html.twig',
            [
                'username'  => $userName,
                'sitename'  => $siteName,
                'login_url' => $loginUrl,
                'login'     => $login,
                'password'  => $password,
            ]
        );

        $subject = $this->translator->trans(
            'ekyna_user.email.creation.subject',
            ['%sitename%' => $siteName]
        );

        return $this->sendEmail($rendered, $user->getEmail(), $userName, $subject);
    }
1135462
public function update(User $user, User $entity)
    {
        if ($entity->id === $user->id) {
            return true;
        }
        return $user->hasPermission('user-update');
    }
314156
public function initSessionByUserToken($userToken) {
      $response = $this->request('get', 'initSession', ['headers' => ['Authorization' => "user_token $userToken"]]);
      if ($response->getStatusCode() != 200
         || !$this->sessionToken = json_decode($response->getBody()->getContents(), true)['session_token']) {
         $body = json_decode($response->getBody()->getContents());
         throw new Exception(ErrorHandler::getMessage($body[0]));
      }
      return true;
   }
921169
public function sendNotification($user)
  {
    $token = Hash::random(35);

    VerifiedUser::create([
      'email' => $user->email,
      'token' => $token
    ]);

    return $this->sendVerifyEmailNotification($user, $token);
  }
1338954
public function verify( $user, $token ) {

		// Check Token
		if( $user->isVerifyTokenValid( $token ) ) {

			$modelClass	= static::$modelClass;

			// Find existing user
			$userToUpdate = $modelClass::findById( $user->id );

			// User need admin approval
			if( Yii::$app->core->isUserApproval() ) {

				$userToUpdate->verify();
			}
			// Direct approval and activation
			else {

				$userToUpdate->status = User::STATUS_ACTIVE;
			}

			$userToUpdate->unsetVerifyToken();

			$userToUpdate->update();

			return true;
		}

		return false;
	}