Exemplo n.º 1
0
 public function decodeReceipt($receipt)
 {
     if (is_string($receipt) === true) {
         return json_decode(base64_decode($receipt));
     } else {
         if (is_array($receipt) === true) {
             return Utility::arrayToObject($receipt);
         } else {
             if (is_object($receipt) === true) {
                 return $receipt;
             }
         }
     }
 }
Exemplo n.º 2
0
 public function getProfile($token)
 {
     if (empty($this->profile) === true) {
         $client = new Google_Client();
         $client->setClientId(Config::get('google.api.client.id.' . Utility::os()));
         $client->setClientSecret(Config::get('google.api.client.secret.' . Utility::os()));
         $client->addScope('https://www.googleapis.com/auth/userinfo.profile');
         $client->addScope('https://www.googleapis.com/auth/userinfo.email');
         $profile = null;
         if (is_array($token) === true) {
             if (empty($token['idToken']) === false) {
                 //this is a signed id token
                 $ticket = $client->verifyIdToken($token['idToken'])->getAttributes()['payload'];
                 if ($ticket['email'] === $token['email']) {
                     $profile = $token;
                     $profile['id'] = $ticket['sub'];
                 } else {
                     throw new NonFatalException('invalid token, emails dont match');
                 }
             } else {
                 if (empty($token['access_token']) === false) {
                     //regular access token
                     $client->setAccessToken(json_encode($token));
                 } else {
                     throw new NonFatalException('invalid token, no accpetable attribute');
                 }
             }
         } else {
             if (is_string($token) === true) {
                 //token is a CODE to exchange for access token
                 $client->authenticate($token);
             } else {
                 throw new NonFatalException('invalid token, invalid type');
             }
         }
         if (empty($profile) === true) {
             $oauth = new Google_Service_Oauth2($client);
             $profile = $oauth->userinfo->get();
         }
         $this->profile = array('provider' => self::PROVIDER_NAME, 'id' => $profile['id'], 'email' => $profile['email'], 'firstName' => isset($profile['givenName']) ? $profile['givenName'] : null, 'lastName' => isset($profile['familyName']) ? $profile['familyName'] : null);
     }
     return $this->profile;
 }
Exemplo n.º 3
0
 public function getLinks(PropelModelPager $pager)
 {
     $links = array('first' => $this->getFirstPage($pager), 'prev' => $this->getPrevPage($pager), 'next' => $this->getNextPage($pager), 'last' => $this->getLastPage($pager));
     $uri = (empty($_SERVER['SERVER_NAME']) ? '' : Utility::getProtocol() . '://' . $_SERVER['SERVER_NAME']) . (empty($_SERVER['REQUEST_URI']) ? null : $_SERVER['REQUEST_URI']);
     foreach ($links as &$link) {
         if (empty($link) === false) {
             if (Utility::inString(self::PAGE, $uri) === true) {
                 $link = preg_replace('/' . self::PAGE . '=\\d+/', self::PAGE . '=' . $link, $uri);
             } else {
                 $operator = Utility::inString('?', $uri) ? '&' : '?';
                 $link = $uri . $operator . self::PAGE . '=' . $link;
             }
         }
     }
     return $links;
 }
Exemplo n.º 4
0
 protected function email($exceptionInfo)
 {
     $subject = Config::get('env.prefix') . ' error - ' . APPLICATION_ENV;
     $body = array('Text' => array('Data' => json_encode($exceptionInfo, JSON_PRETTY_PRINT)));
     Utility::sendEmail(Config::get('email.admins'), $subject, $body, Config::get('email.system.error'));
 }