controllers/SettingsController.php
public function connect(ClientInterface $client)
    {
        $attributes = $client->getUserAttributes();
        $provider   = $client->getId();
        $clientId   = $attributes['id'];

        $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId);

        if ($account === null) {
            $account = \Yii::createObject([
                'class'     => Account::className(),
                'provider'  => $provider,
                'client_id' => $clientId,
                'data'      => json_encode($attributes),
                'user_id'   => \Yii::$app->user->id,
            ]);
            $account->save(false);
            \Yii::$app->session->setFlash('success', \Yii::t('user', 'Your account has been connected'));
        } else if (null == $account->user) {
            $account->user_id = \Yii::$app->user->id;
            $account->save(false);
        } else {
            \Yii::$app->session->setFlash('error', \Yii::t('user', 'This account has already been connected to another user'));
        }

        $this->action->successUrl = Url::to(['/user/settings/networks']);
    }
public function connect(ClientInterface $client)
    {
        $attributes = $client->getUserAttributes();
        $provider   = $client->getId();
        $clientId   = $attributes['id'];

        $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId);

        if ($account === null) {
            $account = \Yii::createObject([
                'class'     => Account::className(),
                'provider'  => $provider,
                'client_id' => $clientId,
                'data'      => json_encode($attributes),
                'user_id'   => \Yii::$app->user->id,
            ]);
            $account->save(false);
            \Yii::$app->session->setFlash('success', \Yii::t('user', 'Your account has been connected'));
        } else if (null == $account->user) {
            $account->user_id = \Yii::$app->user->id;
            $account->save(false);
        } else {
            \Yii::$app->session->setFlash('error', \Yii::t('user', 'This account has already been connected to another user'));
        }

        $this->action->successUrl = Url::to(['/user/settings/networks']);
    }
public function connect ( ClientInterface $ client ) { $ attributes = $ client -> getUserAttributes ( ) ; $ provider = $ client -> getId ( ) ; $ clientId = $ attributes [ 'id' ] ; $ account = $ this -> finder -> findAccountByProviderAndClientId ( $ provider , $ clientId ) ; if ( $ account === null ) { $ account = \ Yii :: createObject ( [ 'class' => Account :: className ( ) , 'provider' => $ provider , 'client_id' => $ clientId , 'data' => json_encode ( $ attributes ) , 'user_id' => \ Yii :: $ app -> user -> id , ] ) ; $ account -> save ( false ) ; \ Yii :: $ app -> session -> setFlash ( 'success' , \ Yii :: t ( 'user' , 'Your account has been connected' ) ) ; } else if ( null == $ account -> user ) { $ account -> user_id = \ Yii :: $ app -> user -> id ; $ account -> save ( false ) ; } else { \ Yii :: $ app -> session -> setFlash ( 'error' , \ Yii :: t ( 'user' , 'This account has already been connected to another user' ) ) ; } $ this -> action -> successUrl = Url :: to ( [ '/user/settings/networks' ] ) ; }
Connects social account to user.
@param  ClientInterface $client
@return \yii\web\Response
Connects social account to user .