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


PHP Finder::findAccountByProviderAndClientId方法代码示例

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


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

示例1: connect

 /**
  * 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', 'Account has been successfully connected'));
     } 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']);
 }
开发者ID:kongoon,项目名称:yii2-user,代码行数:20,代码来源:SettingsController.php

示例2: 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 = $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)) {
         $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id]);
     } else {
         \Yii::$app->user->login($user, $this->module->rememberFor);
     }
 }
开发者ID:uniwizardcom,项目名称:yii2-task,代码行数:21,代码来源:SecurityController.php


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