Exemplo n.º 1
0
 /**
  * Returns the user data stored trough the Genetsis ID personal identifier.
  * The identifiers could be: id (ckusid), screenName, email, dni
  * Sample: array('id'=>'XXXX','screenName'=>'xxxx');
  *
  * @param array The Genetsis IDs identifier to search, 'identifier' => 'value'
  * @return array A vector of {@link User} objects with user's
  *     personal data. The array could be empty.
  * @throws /Exception
  */
 public static function getUsers($identifiers)
 {
     $druid_user = array();
     if (is_array($identifiers)) {
         try {
             if (!($druid_user_data = FileCache::get('user-' . reset($identifiers)))) {
                 Identity::getLogger()->debug('Identifier: ' . reset($identifiers) . ' is Not in Cache System');
                 $client_token = Identity::getThings()->getClientToken();
                 if (is_null($client_token)) {
                     throw new Exception('The clientToken is empty');
                 }
                 /**
                  * Parameters:
                  * oauth_token: client token
                  * s (select): dynamic user data to be returned
                  * f (from): User
                  * w (where): param with OR w.param1&w.param2...
                  */
                 $params = array();
                 $params['oauth_token'] = $client_token->getValue();
                 $params['s'] = "*";
                 $params['f'] = "User";
                 foreach ($identifiers as $key => $val) {
                     $params['w.' . $key] = $val;
                 }
                 $base = OAuthConfig::getApiUrl('api.user', 'base_url');
                 $api = OAuthConfig::getApiUrl('api.user', 'user');
                 $response = Request::execute($base . $api, $params, Request::HTTP_POST);
                 if ($response['code'] != 200 || !isset($response['result']->data) || $response['result']->count == '0') {
                     throw new Exception('The data retrieved is empty');
                 }
                 $druid_user = $response['result']->data;
                 FileCache::set('user-' . reset($identifiers), $druid_user, self::USER_TTL);
             } else {
                 Identity::getLogger()->debug('Identifier: ' . reset($identifiers) . ' is in Cache System');
                 $druid_user = json_decode(json_encode($druid_user_data));
             }
         } catch (Exception $e) {
             Identity::getLogger()->error($e->getMessage());
         }
     }
     return $druid_user;
 }
Exemplo n.º 2
0
 /**
  * Checks if the user has accepted terms and conditions for the specified section (scope).
  *
  * @param string $endpoint_url The endpoint where the request will be sent.
  * @param string $scope Section-key identifier of the web client. The section-key is located in "oauthconf.xml" file.
  * @return boolean TRUE if the user need to accept the terms and conditions (not accepted yet) or
  *      FALSE if it has already accepted them (no action required).
  * @throws \Exception If there is an error.
  */
 public static function doCheckUserNeedAcceptTerms($endpoint_url, $scope)
 {
     try {
         if (($endpoint_url = trim((string) $endpoint_url)) == '') {
             throw new Exception('Endpoint URL is empty');
         }
         if (($scope = trim((string) $scope)) == '') {
             throw new Exception('Scope is empty');
         }
         if (!($access_token = Identity::getThings()->getAccessToken()) instanceof AccessToken || $access_token->getValue() == '') {
             throw new Exception('Access token is empty');
         }
         // Send request.
         $params = array();
         $params['oauth_token'] = $access_token->getValue();
         $params['s'] = "needsToCompleteData";
         $params['f'] = "UserMeta";
         $params['w.section'] = $scope;
         $response = Request::execute($endpoint_url, $params, Request::HTTP_POST);
         self::checkErrors($response);
         if (isset($response['code']) && $response['code'] == 200) {
             return call_user_func(function ($result) {
                 if (isset($result->data) && is_array($result->data)) {
                     foreach ($result->data as $data) {
                         if (isset($data->meta->name) && $data->meta->name === 'needsToAcceptTerms') {
                             return isset($data->meta->value) && $data->meta->value === 'true';
                         }
                     }
                 }
                 return false;
             }, $response['result']);
         } else {
             return false;
         }
     } catch (Exception $e) {
         throw new Exception('Error [' . __FUNCTION__ . '] - ' . $e->getMessage());
     }
 }