当前位置: 首页>>代码示例>>PHP>>正文


PHP ClientInterface::getId方法代码示例

本文整理汇总了PHP中yii\authclient\ClientInterface::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::getId方法的具体用法?PHP ClientInterface::getId怎么用?PHP ClientInterface::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\authclient\ClientInterface的用法示例。


在下文中一共展示了ClientInterface::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onAuthSuccess

 /**
  * @param $client
  *
  * TODO
  */
 public function onAuthSuccess(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     /* @var $auth UserAuth */
     $auth = UserAuth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             $user = $auth->user;
             Yii::$app->user->login($user);
         } else {
             if (isset($attributes['email']) && User::find()->where(['email' => $attributes['email']])->exists()) {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]);
             } else {
                 if ($client->signIn()) {
                     $this->redirect('/profile');
                 }
             }
         }
     } else {
         if (!$auth) {
             $auth = new UserAuth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
             $auth->save();
         }
     }
 }
开发者ID:mrbighokage,项目名称:book-test-yii2,代码行数:30,代码来源:DefaultController.php

示例2: authSuccessCallback

 /**
  * @param \yii\authclient\ClientInterface $Client
  * @throws \yii\base\NotSupportedException
  */
 public function authSuccessCallback(\yii\authclient\ClientInterface $Client)
 {
     $AuthResponse = new \resources\User\Auth\Response();
     $AuthResponse->client = $Client->getId();
     $attributes = $Client->getUserAttributes();
     $AuthResponse->response = Json::encode($attributes);
     $UserQuery = \resources\User::find();
     switch ($Client->getId()) {
         case 'facebook':
             $UserQuery->byFacebookId($attributes['id']);
             break;
         case 'github':
             $UserQuery->byGithubId($attributes['id']);
             break;
         case 'google':
             $UserQuery->byGoogleId($attributes['id']);
             break;
         case 'linkedin':
             $UserQuery->byLinkedinId($attributes['id']);
             break;
         case 'live':
             $UserQuery->byLiveId($attributes['id']);
             break;
         case 'twitter':
             $UserQuery->byTwitterId($attributes['id']);
             break;
         case 'vkontakte':
             $UserQuery->byVkontakteId($attributes['id']);
             break;
         case 'yandex':
             $UserQuery->byYandexId($attributes['id']);
             break;
     }
     /** @var \resources\User $User */
     $User = $UserQuery->one();
     if ($User instanceof \resources\User) {
         $AuthResponse->result = Json::encode($User->id);
     } else {
         $User = new \resources\User();
         $User->appendClientAttributes($Client);
         if ($User->save()) {
             $User->createSocialLink($Client);
             $AuthResponse->result = Json::encode($User->id);
             AuthManager()->assign(RbacFactory::Role(\frontend\Permissions::ROLE_USER), $User->id);
         } else {
             $AuthResponse->result = Json::encode($User->getErrors());
         }
     }
     $AuthResponse->save();
     if ($User instanceof \resources\User && !$User->isNewRecord) {
         $User->save();
         User()->login($User, 86400);
     }
 }
开发者ID:rmrevin,项目名称:yii2-application,代码行数:58,代码来源:SignController.php

示例3: createClientUrl

 /**
  * Composes client auth URL.
  * @param ClientInterface $provider external auth client instance.
  * @return string auth URL.
  */
 public function createClientUrl($provider)
 {
     $this->autoRender = false;
     $url = $this->getBaseAuthUrl();
     $url[$this->clientIdGetParamName] = $provider->getId();
     return Url::to($url);
 }
开发者ID:sankam-nikolya,项目名称:yii2-users,代码行数:12,代码来源:AuthKeysManager.php

示例4: createLog

 /**
  * @param \yii\authclient\ClientInterface $Client
  * @return static
  */
 public static function createLog(\yii\authclient\ClientInterface $Client)
 {
     $AuthResponse = new static();
     $AuthResponse->client = $Client->getId();
     $attributes = $Client->getUserAttributes();
     $AuthResponse->response = Json::encode($attributes);
     return $AuthResponse;
 }
开发者ID:cookyii,项目名称:module-account,代码行数:12,代码来源:Model.php

示例5: onAuthSuccess

 /**
  * @param ClientInterface $client
  */
 public function onAuthSuccess($client)
 {
     $attributes = $client->getUserAttributes();
     $email = ArrayHelper::getValue($attributes, 'email');
     /** @var Auth $auth */
     $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             // login
             $user = $auth->user;
             Yii::$app->user->login($user, 3600 * 24 * 30);
         } else {
             // signup
             if (User::find()->where(['email' => $email])->exists()) {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]);
             } else {
                 $password = Yii::$app->security->generateRandomString(6);
                 $user = new User(['username' => $attributes['login'], 'email' => $email, 'password' => $password]);
                 $user->generateAuthKey();
                 $user->generatePasswordResetToken();
                 $transaction = $user->getDb()->beginTransaction();
                 if ($user->save()) {
                     $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
                     if ($auth->save()) {
                         $transaction->commit();
                         Yii::$app->user->login($user, 3600 * 24 * 30);
                     } else {
                         print_r($auth->getErrors());
                         die;
                     }
                 } else {
                     print_r($user->getErrors());
                     die;
                 }
             }
         }
     } else {
         // user already logged in
         if (!$auth) {
             // add auth provider
             $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
             $auth->save();
         }
     }
 }
开发者ID:hucongyang,项目名称:yiiframework.com,代码行数:48,代码来源:SiteController.php

示例6: byClient

 /**
  * Finds an account by client.
  * @param  ClientInterface $client
  * @return AccountQuery
  */
 public function byClient(ClientInterface $client)
 {
     //xiaoma update
     //qq and sina 's attr has no id
     $client_type = $client->getId();
     switch ($client_type) {
         case 'qq':
             $client_id = $client->getUserAttributes()['openid'];
             break;
         case 'sina':
             $client_id = $client->getUserAttributes()['uid'];
             break;
         default:
             $client_id = $client->getUserAttributes()['id'];
             break;
     }
     return $this->andWhere(['provider' => $client->getId(), 'client_id' => $client_id]);
 }
开发者ID:wangwillout,项目名称:yii2-user,代码行数:23,代码来源:AccountQuery.php

示例7: clientLink

 /**
  * Меняем ссылки на добавление и удаление ключей
  * @param ClientInterface $client external auth client instance.
  * @param string $text link text, if not set - default value will be generated.
  * @param array $htmlOptions link HTML options.
  * @throws InvalidConfigException on wrong configuration.
  */
 public function clientLink($client, $text = null, array $htmlOptions = [])
 {
     echo Html::beginTag('div', ['class' => 'col-xs-4']);
     $exists = UserOauthKey::findOne(['user_id' => Yii::$app->user->id, 'provider_id' => UserOauthKey::getAvailableClients()[$client->getId()]]);
     if ($exists) {
         $button = Html::a('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-xs">' . Yii::t('user', 'Удалить') . '</span>', Url::toRoute(['auth/unbind', 'id' => $client->getId()]), ['class' => 'btn btn-danger btn-sm', 'onclick' => '$(this).off("click"); return true;']);
     } else {
         $viewOptions = $client->getViewOptions();
         if (isset($viewOptions['popupWidth'])) {
             $htmlOptions['data-popup-width'] = $viewOptions['popupWidth'];
         }
         if (isset($viewOptions['popupHeight'])) {
             $htmlOptions['data-popup-height'] = $viewOptions['popupHeight'];
         }
         $htmlOptions['class'] = 'btn btn-success btn-sm';
         $button = Html::a('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="hidden-xs">' . Yii::t('user', 'Добавить') . '</span>', $this->createClientUrl($client), $htmlOptions);
     }
     echo Html::tag('span', $button, ['class' => 'auth-icon ' . $client->getName(), 'style' => 'padding-left: 40px; margin-bottom: 10px;']);
     echo Html::endTag('div');
 }
开发者ID:lowbase,项目名称:yii2-user,代码行数:27,代码来源:AuthKeysManager.php

示例8: appendClientAttributes

 /**
  * @param \yii\authclient\ClientInterface $Client
  * @throws \yii\base\NotSupportedException
  */
 public function appendClientAttributes(\yii\authclient\ClientInterface $Client)
 {
     /** @var \cookyii\modules\Account\resources\Account\Model $self */
     $self = $this;
     $attributes = $Client->getUserAttributes();
     switch ($Client->getId()) {
         default:
             $attributes = null;
             break;
         case 'facebook':
             $attributes = $this->appendFacebookAttributes($attributes);
             break;
         case 'instagram':
             $attributes = $this->appendInstagramAttributes($attributes);
             break;
         case 'github':
             $attributes = $this->appendGithubAttributes($attributes);
             break;
         case 'google':
             $attributes = $this->appendGoogleAttributes($attributes);
             break;
         case 'linkedin':
             $attributes = $this->appendLinkedinAttributes($attributes);
             break;
         case 'live':
             $attributes = $this->appendLiveAttributes($attributes);
             break;
         case 'twitter':
             $attributes = $this->appendTwitterAttributes($attributes);
             break;
         case 'vkontakte':
             $attributes = $this->appendVkontakteAttributes($attributes);
             break;
         case 'yandex':
             $attributes = $this->appendYandexAttributes($attributes);
             break;
         case 'odnoklassniki':
             $attributes = $this->appendOdnoklassnikiAttributes($attributes);
             break;
     }
     if (!empty($attributes)) {
         foreach ($attributes as $key => $value) {
             $attr = $self->getAttribute($key);
             if ($self->hasAttribute($key) && empty($attr)) {
                 $self->setAttribute($key, $value);
             }
         }
     }
 }
开发者ID:cookyii,项目名称:module-account,代码行数:53,代码来源:SocialTrait.php

示例9: authenticate

 /**
  * Logs the user in if this social account has been already used. Otherwise shows registration form.
  *
  * @param  ClientInterface $client
  * @return \yii\web\Response
  */
 public function authenticate(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     $provider = $client->getId();
     $clientId = $attributes['id'];
     if (null === ($account = $this->module->manager->findAccount($provider, $clientId))) {
         $account = $this->module->manager->createAccount(['provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes)]);
         $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);
     }
 }
开发者ID:ilyar,项目名称:dektrium-yii2-user,代码行数:21,代码来源:SecurityController.php

示例10: authenticate

 public function authenticate(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     $provider = $client->getId();
     $clientId = $attributes['id'];
     $model = SocialAccount::find()->where(['provider' => $provider, 'client_id' => $clientId])->one();
     if ($model === NULL) {
         $model->save(FALSE);
     }
     if (NULL === ($user = $model->getUser())) {
         $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $model->id]);
     } else {
         Yii::$app->user->login($user, UserModule::$rememberMeDuration);
     }
 }
开发者ID:fabristyle,项目名称:yii2-user-1,代码行数:15,代码来源:AuthController.php

示例11: authenticate

 /**
  * Logs the user in if this social account has been already used. Otherwise shows registration form.
  * @param  ClientInterface $client
  * @return \yii\web\Response
  */
 public function authenticate(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     $provider = $client->getId();
     $clientId = $attributes['id'];
     $account = UserAccount::find()->where(['provider' => $provider, 'client_id' => $clientId])->one();
     if ($account === null) {
         $account = \Yii::createObject(['class' => UserAccount::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes), 'created_at' => time()]);
         $account->save(false);
     }
     if (null === ($user = $account->user)) {
         $this->action->successUrl = Url::to(['/site/connect', 'account_id' => $account->id]);
     } else {
         \Yii::$app->user->login($user, 1209600);
         // two weeks
     }
 }
开发者ID:grutabow,项目名称:getyii,代码行数:22,代码来源:SecurityController.php

示例12: clientLogin

 /**
  * Invoked after a successful authentication with a client.
  *
  * @param ClientInterface $client client instance.
  * @return \yii\web\Response
  */
 public function clientLogin(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     $name = $client->getId();
     $dataContract = $this->module->getDataContract();
     $provider = $dataContract->findProvider(['name' => $name, 'clientId' => $attributes['id']]);
     if ($provider === null) {
         $provider = $dataContract->createProvider(['attributes' => ['name' => $name, 'clientId' => $attributes['id'], 'data' => $attributes]]);
         if (!$provider->save(false)) {
             $this->fatalError();
         }
     }
     if ($provider->account !== null) {
         Yii::$app->user->login($provider->account, Module::getParam(Module::PARAM_LOGIN_EXPIRE_TIME));
         return $this->goHome();
     } else {
         return $this->redirect([Module::URL_ROUTE_CONNECT, 'providerId' => $provider->id]);
     }
 }
开发者ID:bogiesoft,项目名称:yii2-account,代码行数:25,代码来源:AuthController.php

示例13: authenticate

 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);
     }
 }
开发者ID:kd-brinex,项目名称:kd,代码行数:20,代码来源:SecurityController.php

示例14: appendClientAttributes

 /**
  * @param \yii\authclient\ClientInterface $Client
  * @throws \yii\base\NotSupportedException
  */
 public function appendClientAttributes(\yii\authclient\ClientInterface $Client)
 {
     $attributes = $Client->getUserAttributes();
     switch ($Client->getId()) {
         default:
             $attributes = null;
             break;
         case 'facebook':
             $attributes = $this->aggregateFacebookAttributes($attributes);
             break;
         case 'github':
             $attributes = $this->aggregateGithubAttributes($attributes);
             break;
         case 'google':
             $attributes = $this->aggregateGoogleAttributes($attributes);
             break;
         case 'linkedin':
             $attributes = $this->aggregateLinkedinAttributes($attributes);
             break;
         case 'live':
             $attributes = $this->aggregateLiveAttributes($attributes);
             break;
         case 'twitter':
             $attributes = $this->aggregateTwitterAttributes($attributes);
             break;
         case 'vkontakte':
             $attributes = $this->aggregateVkontakteAttributes($attributes);
             break;
         case 'yandex':
             $attributes = $this->aggregateYandexAttributes($attributes);
             break;
     }
     if (!empty($attributes)) {
         $this->setAttributes($attributes);
     }
 }
开发者ID:arooth,项目名称:module-account,代码行数:40,代码来源:UserSocialTrait.php

示例15: findAccountByClient

 /**
  * Finds an account by client.
  * @param ClientInterface $client
  * @return models\Account|null
  */
 public function findAccountByClient(ClientInterface $client)
 {
     return $this->accountQuery->where(['provider' => $client->getId(), 'client_id' => $client->getUserAttributes()['id']])->one();
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:9,代码来源:Finder.php


注:本文中的yii\authclient\ClientInterface::getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。