示例#1
0
 /**
  * get url redirect to a specified opi
  */
 public static function get($opi = false, $redirect_url = false)
 {
     if (!$opi) {
         $opi = OAuthConfig::getOpi();
     }
     if (!$opi) {
         throw new Exception("You must pass OPI as param, or define it in <data> part of oauthconf.xml");
     }
     $params = array("id" => urlencode(UserApi::getUserLoggedOid()), "sc" => urlencode(OAuthConfig::getBrand()), "carry_url" => urlencode($redirect_url));
     $info = UserApi::getUserLogged();
     $opi_age = false;
     $opi_gender = false;
     try {
         $birthday = isset($info->user->user_data->birthday) ? $info->user->user_data->birthday->value : null;
         if ($birthday != null) {
             $birthday = explode("/", $birthday);
             $age = date("md", date("U", mktime(0, 0, 0, $birthday[2], $birthday[1], $birthday[0]))) > date("md") ? date("Y") - $birthday[2] - 1 : date("Y") - $birthday[2];
             if (18 <= $age && $age <= 24) {
                 $opi_age = 1;
             } else {
                 if (25 <= $age && $age <= 34) {
                     $opi_age = 2;
                 }
             }
             if (35 <= $age && $age <= 44) {
                 $opi_age = 3;
             }
             if (45 <= $age && $age <= 64) {
                 $opi_age = 4;
             }
         }
     } catch (Exception $e) {
     }
     try {
         $gender = isset($info->user->user_data->gender) ? $info->user->user_data->gender->vid : null;
         if ($gender == 1) {
             $opi_gender = 2;
         } else {
             if ($gender == 2) {
                 $opi_gender = 1;
             }
         }
     } catch (Exception $e) {
     }
     if ($opi_age) {
         $params["carry_edad"] = $opi_age;
     }
     if ($opi_gender) {
         $params["carry_sexo"] = $opi_gender;
     }
     $query = array();
     foreach ($params as $param => $value) {
         $query[] = "{$param}={$value}";
     }
     return OAuthConfig::getApiUrl('opi', 'base_url') . OAuthConfig::getApiUrl('opi', 'rules') . "/" . $opi . "?" . implode('&', $query);
 }
示例#2
0
 /**
  * Checks if the user needs to accept terms and conditions for that section.
  *
  * The "scope" (section) is a group of fields configured in DruID for
  * a web client.
  *
  * A section can be also defined as a "part" (section) of the website
  * (web client) that only can be accessed by a user who have filled a
  * set of personal information configured in DruID.
  *
  * @param $scope string Section-key identifier of the web client. The
  *     section-key is located in "oauthconf.xml" file.
  * @throws \Exception
  * @return boolean TRUE if the user need to accept terms and conditions, FALSE if it has
  *      already accepted them.
  */
 public static function checkUserNeedAcceptTerms($scope)
 {
     $status = false;
     try {
         self::$logger->info('Checking if the user has accepted terms and conditions for this section:' . $scope);
         if (self::isConnected()) {
             $status = OAuth::doCheckUserNeedAcceptTerms(OAuthConfig::getApiUrl('api.user', 'base_url') . OauthConfig::getApiUrl('api.user', 'user'), $scope);
         }
     } catch (Exception $e) {
         self::$logger->error($e->getMessage());
     }
     return $status;
 }
示例#3
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;
 }