/**
  * Tries to connect social account to user.
  *
  * @param ClientInterface $client
  */
 public function connect(ClientInterface $client)
 {
     /** @var Account $account */
     $account = Yii::createObject(Account::className());
     $event = $this->getAuthEvent($account, $client);
     $this->trigger(self::EVENT_BEFORE_CONNECT, $event);
     $account->connectWithUser($client);
     $this->trigger(self::EVENT_AFTER_CONNECT, $event);
     $this->action->successUrl = Url::to(['/users/settings/networks']);
 }
Exemple #2
0
 /**
  * Tries to find account, otherwise creates new account.
  *
  * @param BaseClientInterface $client
  *
  * @return Account
  * @throws \yii\base\InvalidConfigException
  */
 protected static function fetchAccount(BaseClientInterface $client)
 {
     $account = self::find()->byClient($client)->one();
     if (null === $account) {
         /** @var Account $account */
         $account = Yii::createObject(['class' => Account::className(), 'provider' => $client->getId(), 'clientId' => $client->getUserAttributes()['id'], 'data' => Json::encode($client->getUserAttributes())]);
         $account->save(false);
     }
     return $account;
 }