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


PHP ClientInterface::getName方法代码示例

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


在下文中一共展示了ClientInterface::getName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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(['game/index'], true));
         } else {
             Yii::info('ExternalUser is not registered. Redirecting to site/signup.');
             Yii::$app->session->set('game/register/authProviderName', $client->getName());
             Yii::$app->session->set('game/register/authProviderTitle', $client->getTitle());
             Yii::$app->session->set('game/register/attributes', $attributes);
             return $this->action->redirect(Url::to(['site/signup'], true));
         }
     } 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,代码行数:36,代码来源:SiteController.php

示例3: autorizar

 /**
  * Red Social
  */
 public function autorizar()
 {
     $attributes = $this->client->getUserAttributes();
     $model = new LoginRedSocialForm();
     $model->red_social = $this->client->getName();
     $model->perfil_id = $attributes['id'];
     $model->correo = isset($attributes['email']) ? $attributes['email'] : null;
     $model->nombre = $attributes['first_name'];
     $model->apellido = $attributes['last_name'];
     $model->genero = $attributes['gender'];
     $model->url_perfil = $attributes['link'];
     $model->localidad = $attributes['locale'];
     $model->estado = $attributes['verified'];
     $model->access_token = $this->token_acces;
     $model->imagen = $this->getImagenPerfilFacebook($attributes['id']);
     //Set return url if the user is authenticated. AuthAction will handle the redirect
     if ($returnUrl = $model->autenticarUsuario()) {
         \Yii::$app->user->setReturnUrl($returnUrl);
     }
 }
开发者ID:alejandrososa,项目名称:AB,代码行数:23,代码来源:AuthRedSocial.php

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

示例5: clientLink

 /**
  * Outputs client auth link.
  * @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.
  * @return string generated HTML.
  * @throws InvalidConfigException on wrong configuration.
  */
 public function clientLink($client, $text = null, array $htmlOptions = [])
 {
     $viewOptions = $client->getViewOptions();
     if (empty($viewOptions['widget'])) {
         if ($text === null) {
             $text = Html::tag('span', '', ['class' => 'auth-icon ' . $client->getName()]);
         }
         if (!isset($htmlOptions['class'])) {
             $htmlOptions['class'] = $client->getName();
         }
         if (!isset($htmlOptions['title'])) {
             $htmlOptions['title'] = $client->getTitle();
         }
         Html::addCssClass($htmlOptions, ['widget' => 'auth-link']);
         if ($this->popupMode) {
             if (isset($viewOptions['popupWidth'])) {
                 $htmlOptions['data-popup-width'] = $viewOptions['popupWidth'];
             }
             if (isset($viewOptions['popupHeight'])) {
                 $htmlOptions['data-popup-height'] = $viewOptions['popupHeight'];
             }
         }
         return Html::a($text, $this->createClientUrl($client), $htmlOptions);
     }
     $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;
     return $widgetClass::widget($widgetConfig);
 }
开发者ID:yiisoft,项目名称:yii2-authclient,代码行数:46,代码来源:AuthChoice.php

示例6: clientLink

 /**
  * Outputs client auth link.
  * @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.
  */
 public function clientLink($client, $text = null, array $htmlOptions = [])
 {
     if ($text === null) {
         $text = Html::tag('span', '', ['class' => 'auth-icon ' . $client->getName()]);
         $text .= Html::tag('span', $client->getTitle(), ['class' => 'auth-title']);
     }
     if (!array_key_exists('class', $htmlOptions)) {
         $htmlOptions['class'] = 'auth-link ' . $client->getName();
     }
     if ($this->popupMode) {
         $viewOptions = $client->getViewOptions();
         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);
 }
开发者ID:cakpep,项目名称:spk-tht,代码行数:26,代码来源:AuthChoice.php

示例7: createClientUrl

 /**
  * Composes client auth URL.
  * @param \yii\authclient\ClientInterface $client external auth client instance.
  * @return string auth URL.
  */
 public function createClientUrl($client)
 {
     return '/site/auth?authclient=' . $client->getName();
 }
开发者ID:bessonov87,项目名称:bw,代码行数:9,代码来源:AuthChoice.php

示例8: handle

 /**
  * handle
  */
 public function handle()
 {
     $attributes = $this->client->getUserAttributes();
     // common
     $continue = false;
     $id = ArrayHelper::getValue($attributes, 'id');
     $fullname = '';
     $email = '';
     // google
     if ($this->client->getName() == 'google') {
         $fullname = ArrayHelper::getValue($attributes, 'displayName');
         $emails = ArrayHelper::getValue($attributes, 'emails');
         $email = $emails[0]['value'];
         $continue = true;
     }
     // facebook
     if ($this->client->getName() == 'facebook') {
         $fullname = ArrayHelper::getValue($attributes, 'name');
         $email = ArrayHelper::getValue($attributes, 'email');
         $continue = true;
     }
     if (!$continue) {
         //            Yii::$app->getSession()->setFlash('info', [
         //                Yii::t('app', 'Flickr'),
         //            ]);
         //Yii::$app->user->setReturnUrl(Yii::$app->request->referrer);
         return;
     }
     /* @var Auth $auth */
     $auth = Auth::find()->where(['source' => $this->client->getId(), 'source_id' => $id])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             // login
             /* @var Account $user */
             $user = $auth->user;
             $this->updateUserInfo($user);
             Yii::$app->user->login($user, Setting::getValue('rememberMeDuration'));
         } else {
             // signup
             if ($email !== null && Account::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' => $this->client->getTitle()])]);
             } else {
                 $password = Yii::$app->security->generateRandomString(6);
                 $user = new Account(['fullname' => $fullname, 'email' => $email, 'password' => $password]);
                 $user->generateAuthKey();
                 $user->generatePasswordResetToken();
                 $transaction = Account::getDb()->beginTransaction();
                 //file_put_contents('D:\log', json_encode($transaction));
                 if ($user->save()) {
                     $auth = new Auth(['user_id' => $user->id, 'source' => $this->client->getId(), 'source_id' => (string) $id]);
                     if ($auth->save()) {
                         $transaction->commit();
                         Yii::$app->user->login($user, Setting::getValue('rememberMeDuration'));
                     } else {
                         $transaction->rollBack();
                         Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to save {client} account: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($auth->getErrors())])]);
                     }
                 } else {
                     $transaction->rollBack();
                     Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to save user: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($user->getErrors())])]);
                 }
             }
         }
     } else {
         // user already logged in
         Yii::$app->user->setReturnUrl(Yii::$app->request->referrer);
         if (!$auth) {
             // add auth provider
             $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $this->client->getId(), 'source_id' => (string) $attributes['id']]);
             if ($auth->save()) {
                 /** @var Account $user */
                 $user = $auth->user;
                 $this->updateUserInfo($user);
                 Yii::$app->getSession()->setFlash('success', [Yii::t('app', 'Linked {client} account.', ['client' => $this->client->getTitle()])]);
             } else {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to link {client} account: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($auth->getErrors())])]);
             }
         } else {
             // there's existing auth
             Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to link {client} account. There is another user using it.', ['client' => $this->client->getTitle()])]);
         }
     }
 }
开发者ID:modernkernel,项目名称:yii2-skeleton,代码行数:86,代码来源:AuthHandler.php


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