Exemplo n.º 1
0
 public function successCallback($client)
 {
     $attributes = (object) $client->getUserAttributes();
     $clientClass = get_class($client);
     $validUser = false;
     switch ($clientClass) {
         case "yii\\authclient\\clients\\Facebook":
             if (isset($attributes->email)) {
                 $firstName = $attributes->first_name;
                 $lastName = $attributes->last_name;
                 $email = $attributes->email;
                 $accessToken = $attributes->id;
                 $providerId = 1;
                 $validUser = true;
             }
             break;
         case "yii\\authclient\\clients\\GoogleOAuth":
             if (isset($attributes->emails[0]['value'])) {
                 $firstName = $attributes->name['givenName'];
                 $lastName = $attributes->name['familyName'];
                 $email = $attributes->emails[0]['value'];
                 $accessToken = $attributes->id;
                 $providerId = 2;
                 $validUser = true;
             }
             break;
         case "dektrium\\user\\clients\\Twitter":
             if (isset($attributes->email)) {
                 $firstName = $attributes->first_name;
                 $lastName = $attributes->last_name;
                 $email = $attributes->emails;
                 $accessToken = $attributes->id;
                 $providerId = 3;
                 $validUser = true;
             }
             break;
         default:
             break;
     }
     $model = new LoginForm();
     if ($email != '') {
         $socialInfo = array();
         $socialInfo['email'] = $email;
         $socialInfo['firstName'] = $firstName;
         $socialInfo['lastName'] = $lastName;
         $socialData = $model->socialmediaInsert($socialInfo);
     }
 }