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


PHP authclient\ClientInterface类代码示例

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


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

示例1: clientLink

 /**
  * Добавляем обрамление div
  * @param ClientInterface $client
  * @param null $text
  * @param array $htmlOptions
  * @throws InvalidConfigException
  */
 public function clientLink($client, $text = null, array $htmlOptions = [])
 {
     echo Html::beginTag('div', ['class' => $this->clientCssClass]);
     $text = Html::tag('span', $text, ['class' => 'auth-icon ' . $client->getName()]);
     if (!array_key_exists('class', $htmlOptions)) {
         $htmlOptions['class'] = 'auth-link ' . $client->getName();
     }
     $viewOptions = $client->getViewOptions();
     if (empty($viewOptions['widget'])) {
         if ($this->popupMode) {
             if (isset($viewOptions['popupWidth'])) {
                 $htmlOptions['data-popup-width'] = $viewOptions['popupWidth'];
             }
             if (isset($viewOptions['popupHeight'])) {
                 $htmlOptions['data-popup-height'] = $viewOptions['popupHeight'];
             }
         }
         echo Html::a($text, $this->createClientUrl($client), $htmlOptions) . '<br>';
     } else {
         $widgetConfig = $viewOptions['widget'];
         if (!isset($widgetConfig['class'])) {
             throw new InvalidConfigException('Widget config "class" parameter is missing');
         }
         /* @var $widgetClass Widget */
         $widgetClass = $widgetConfig['class'];
         if (!is_subclass_of($widgetClass, AuthChoiceItem::className())) {
             throw new InvalidConfigException('Item widget class must be subclass of "' . AuthChoiceItem::className() . '"');
         }
         unset($widgetConfig['class']);
         $widgetConfig['client'] = $client;
         $widgetConfig['authChoice'] = $this;
         echo $widgetClass::widget($widgetConfig);
     }
     echo Html::endTag('div');
 }
开发者ID:lowbase,项目名称:yii2-user,代码行数:42,代码来源:AuthChoice.php

示例2: 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

示例3: successCallback

 /**
  * 
  * @param \yii\authclient\ClientInterface $client
  * @return type
  */
 public function successCallback($client)
 {
     // TODO: Group FK's to one local user.
     //       Otherwise, if we log in via FB and another time via google, we
     //       end up with two local accounts.
     if (!$this->action instanceof \yii\authclient\AuthAction) {
         throw new \yii\base\InvalidCallException("successCallback is only meant to be executed by AuthAction!");
     }
     $attributes = $client->getUserAttributes();
     $externalUser = new AuthForm();
     $externalUser->authProvider = $client->getName();
     $externalUser->externalUserId = array_key_exists('id', $attributes) ? $attributes['id'] : null;
     if ($externalUser->validate()) {
         Yii::info('AuthForm validated.');
         if ($externalUser->isRegistered()) {
             Yii::info('ExternalUser is registered. Logging in and redirecting to game/index.');
             $externalUser->login();
             return $this->action->redirect(Url::to(['site/index'], true));
         } else {
             throw new \yii\base\InvalidCallException("Can't login non-registered user '{$externalUser->externalUserId}@{$externalUser->authProvider}'!");
         }
     } else {
         // TODO error. Throw, display actionError?
         Yii::info('AuthForm couldn\'t be validated. Errors: ' . print_r($externalUser->errors, true));
         Yii::info('Client attributes: ' . print_r($attributes, true));
     }
 }
开发者ID:iw-reload,项目名称:iw,代码行数:32,代码来源:SiteController.php

示例4: findSocialProfile

 /**
  * Ищет в базе и возвращает авторизующийся социальный профиль.
  * Если не найден — сохраняет и возвращает.
  *
  * @param ClientInterface $client
  *
  * @throws Exception
  * @return SocialProfile
  */
 protected function findSocialProfile(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     if (null === ($profile = SocialProfile::findOne(['socialId' => $attributes['user_id']]))) {
         $profile = $this->save($attributes);
     }
     return $profile;
 }
开发者ID:sly13,项目名称:maps,代码行数:17,代码来源:SiteController.php

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: social

 public function social(ClientInterface $client)
 {
     $user_data = new UserData($client->getName(), $client->getUserAttributes());
     if (Yii::$app->user->isGuest) {
         $user = User::findSocial($user_data->getObjectName(), $user_data->getObjectName());
         if ($user) {
             Login::login($user);
         } else {
             $user_data->save();
         }
     } else {
         User::saveSocial(Yii::$app->user->identity, $user_data);
     }
     Yii::$app->session->set('social', $client->getName());
 }
开发者ID:kissarat,项目名称:yii2-template,代码行数:15,代码来源:UserController.php

示例10: 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

示例11: authenticate

 public function authenticate(ClientInterface $client)
 {
     // find existing user by service
     if ($this->userService !== null) {
         /** @var User $user */
         $user = Yii::createObject(ModelMapHelper::User());
         $user = $user->loadModel($this->userService->user_id);
         $user->login(UsersModule::module()->loginDuration);
     } else {
         // no user for this pair
         // this is the most hard part
         // create user
         /** @var SocialServiceInterface|BaseClient $client */
         $client->retrieveAdditionalData();
         /** @var RegistrationForm $registrationForm */
         $registrationForm = Yii::createObject(ModelMapHelper::RegistrationForm());
         $this->mapServiceAttributes($client, $registrationForm);
         $user = $registrationForm->socialRegister($client);
         if ($user === false) {
             throw new ErrorException("Unable to register user");
         }
         $userService = $this->createService();
         if ($user->save() === false) {
             throw new ErrorException("Unable to save user:" . var_export($user->errors, true));
         }
         $user->link('services', $userService);
         // check if we need to run post-registration
         $user->login(UsersModule::module()->loginDuration);
         // check if there's some required or recommended fields missing
         foreach (UsersModule::module()->requiredUserAttributes as $attribute) {
             if (empty($user->{$attribute})) {
                 Yii::$app->session->setFlash('info', Yii::t('users', 'Please fill required profile fields.'));
                 $this->redirectToProfileUpdate();
                 return;
             }
         }
         foreach (UsersModule::module()->recommendedUserAttributes as $attribute) {
             if (empty($user->{$attribute})) {
                 //! @todo Add limitation on UsersModule::recommendedFieldsMaxPrompts
                 Yii::$app->session->setFlash('info', Yii::t('users', 'Please fill recommended profile fields.'));
                 $this->redirectToProfileUpdate();
                 return;
             }
         }
     }
 }
开发者ID:cheaterBY,项目名称:yii2-users-module,代码行数:46,代码来源:Social.php

示例12: 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

示例13: oAuthSuccess

 /**
  * This function will be triggered when user is successfuly authenticated using some oAuth client.
  *
  * @param ClientInterface $client
  * @return boolean|Response
  * @throws UnauthorizedHttpException
  */
 public function oAuthSuccess($client)
 {
     // get user data from client
     $userAttributes = $client->getUserAttributes();
     if (isset($userAttributes['emails']) && isset($userAttributes['emails'][0]) && isset($userAttributes['emails'][0]['value'])) {
         $email = $userAttributes['emails'][0]['value'];
         $user = User::find()->byEmail($email)->one();
         if ($user instanceof User) {
             return Yii::$app->user->login($user, 3600 * 24 * 30);
         } else {
             Yii::info('Попытка входа с неразрешенного аккаунта:' . $email . var_export($userAttributes, true), 'site');
             throw new UnauthorizedHttpException('You shall not pass!');
         }
     } else {
         Yii::error('Нет данных аккаунта в ответе OAuth:' . var_export($userAttributes, true), 'site');
         throw new UnauthorizedHttpException('OAuth service error');
     }
 }
开发者ID:Leammas,项目名称:i-hunter,代码行数:25,代码来源:SiteController.php

示例14: 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

示例15: 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


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