예제 #1
0
 public function authenticate($client)
 {
     $attributes = $client->getUserAttributes();
     $provider = $client->getId();
     $clientId = $attributes['id'];
     $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId);
     //var_dump($client->getAccessToken()->params['access_token']);die;
     if ($account === null) {
         $account = \Yii::createObject(['class' => Account::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes), 'token' => $client->getAccessToken()->params['access_token']]);
         $account->save(false);
     }
     if (null === ($user = $account->user)) {
         $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id]);
     } else {
         \Yii::$app->user->login($user, $this->module->rememberFor);
     }
 }
예제 #2
0
 public function authenticate(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)]);
         $account->save(false);
     }
     if (null === ($user = $account->user)) {
         if ($provider == 'kd') {
             $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id, 'provider' => $provider, 'username' => $attributes['username'], 'email' => $attributes['email']]);
         } else {
             $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id]);
         }
     } else {
         \Yii::$app->user->login($user, $this->module->rememberFor);
     }
 }
 /**
  * Tries to connect social account to user.
  *
  * @param ClientInterface $client
  */
 public function connect(ClientInterface $client)
 {
     /** @var Account $account */
     $account = Yii::createObject(Account::className());
     $account->connectWithUser($client);
     $this->action->successUrl = Url::to(['/user/settings/networks']);
 }
 /**
  * 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(['/user/settings/networks']);
 }
예제 #5
0
 /**
  * Connects social account to user.
  * @param  ClientInterface $client
  * @return \yii\web\Response
  */
 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']);
 }
예제 #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAccounts()
 {
     return $this->hasMany(Account::className(), ['user_id' => 'id']);
 }