public function authenticate(ClientInterface $client) {
    $account = Account::find()->byClient($client)->one();

    if (!$this->module->enableRegistration && ($account === null || $account->user === null)) {
      Yii::$app->session->setFlash('danger', Yii::t('users', 'Registration on this website is disabled'));
      $this->action->successUrl = Url::to(['/users/security/login']);
      return;
    }

    if ($account === null) {
      /** @var Account $account */
      $accountObj = Yii::createObject(Account::className());
      $account = $accountObj::create($client);
    }

    $event = $this->getAuthEvent($account, $client);

    $this->trigger(self::EVENT_BEFORE_AUTHENTICATE, $event);

    if ($account->user instanceof User) {
      if ($account->user->isBlocked) {
        Yii::$app->session->setFlash('danger', Yii::t('users', 'Your account has been blocked.'));
        $this->action->successUrl = Url::to(['/users/security/login']);
      } else {
        Yii::$app->user->login($account->user, $this->module->rememberFor);
        $this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
      }
    } else {
      $this->action->successUrl = $account->getConnectUrl();
    }

    $this->trigger(self::EVENT_AFTER_AUTHENTICATE, $event);
  }