Ejemplo n.º 1
0
 public static function create(BaseClientInterface $client)
 {
     /** @var Account $account */
     $account = Yii::createObject(['class' => static::className(), 'provider' => $client->getId(), 'client_id' => $client->getUserAttributes()['id'], 'data' => json_encode($client->getUserAttributes())]);
     if ($client instanceof ClientInterface) {
         $account->setAttributes(['username' => $client->getUsername(), 'email' => $client->getEmail()], false);
     }
     if (($user = static::fetchUser($account)) instanceof User) {
         $account->user_id = $user->id;
     }
     $account->save(false);
     return $account;
 }
Ejemplo n.º 2
0
 public static function create(BaseClientInterface $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'];
             $data = json_encode($client->getUserInfo());
             break;
         case 'sina':
             $client_id = $client->getUserAttributes()['uid'];
             $data = json_encode($client->getUserInfo());
             break;
         default:
             $client_id = $client->getUserAttributes()['id'];
             $data = json_encode($client->getUserAttributes());
             break;
     }
     /** @var Account $account */
     $account = Yii::createObject(['class' => static::className(), 'provider' => $client->getId(), 'client_id' => $client_id, 'data' => $data]);
     if ($client instanceof ClientInterface) {
         $account->setAttributes(['username' => $client->getUsername(), 'email' => $client->getEmail()], false);
     }
     if (($user = static::fetchUser($account)) instanceof User) {
         $account->user_id = $user->id;
     }
     $account->save(false);
     return $account;
 }