Example #1
0
 public function processRegistration($data, &$remember)
 {
     $remember = $this->remember;
     $fcauth = $_COOKIE['fcauth' . $this->siteid];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/friendconnect/api/people/@viewer/@self?fcauth=' . urlencode($fcauth));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $data = json_decode(curl_exec($ch), true);
     curl_close($ch);
     $googleid = null;
     $displayName = null;
     $thumbnailUrl = null;
     if (!is_null($data) && array_key_exists('entry', $data) && array_key_exists('id', $data['entry'])) {
         $googleid = $data['entry']['id'];
         $displayName = $data['entry']['displayName'];
         $thumbnailUrl = $data['entry']['thumbnailUrl'];
     }
     $errors = array();
     if (is_null($googleid)) {
         $errors['googleid'][] = 'No Google Friend Connect user id is passed';
         throw new InputValidationException('No Google Friend Connect user id', 0, $errors);
     }
     $existing_user = User::getUserByGoogleFriendConnectID($googleid);
     if (!is_null($existing_user)) {
         $existing_user->recordActivity(USERBASE_ACTIVITY_LOGIN_GFC);
         return $existing_user;
     }
     if (is_null($displayName)) {
         $errors['username'][] = "User doesn't have display name";
     }
     if (count($errors) > 0) {
         throw new ExistingUserException('User already exists', 0, $errors);
     }
     // ok, let's create a user
     $user = User::createNewGoogleFriendConnectUser($displayName, $googleid, $thumbnailUrl);
     $user->recordActivity(USERBASE_ACTIVITY_REGISTER_GFC);
     return $user;
 }