detectAccess() public method

Keep in mind this method will make an api request to account/APIKeyInfo based on the given \Pheal\Core\Config settings with the given key credentials. More important! This method will throw Exceptions on invalid keys or networks errors So place this call into your try statement
public detectAccess ( ) : boolean | Pheal\Core\Result
return boolean | Pheal\Core\Result
Example #1
0
 /**
  * fetch all kills for $key
  * @static
  * @param array $key
  * @return array
  */
 public static function fetch($key)
 {
     $newkills = 0;
     $oldkills = 0;
     $errors = 0;
     $pheal = new Pheal($key['apiuserid'], $key['apikey']);
     $pheal->detectAccess();
     $characters = $pheal->accountScope->Characters()->characters;
     foreach ($characters as $character) {
         switch ($key['type']) {
             case "Corporation":
                 $pheal->scope = "corp";
                 break;
             case "Account":
                 // account keys are like character keys, just for the complete account
             // account keys are like character keys, just for the complete account
             case "Character":
                 $pheal->scope = "char";
                 break;
             default:
                 // not a key type we can use..
                 continue;
         }
         $kills = $pheal->Killlog(array('characterID' => $character->characterID))->kills;
         $kakp = new \Kingboard\Lib\Parser\EveAPI();
         $info = $kakp->parseKills($kills);
         $oldkills += $info['oldkills'];
         $newkills += $info['newkills'];
         $errors += $info['errors'];
     }
     return array("old" => $oldkills, "new" => $newkills, "total" => $oldkills + $newkills, "errors" => $errors);
 }
Example #2
0
 public function myKingboard(array $parameters)
 {
     $user = \Kingboard\Lib\Auth\Auth::getUser();
     $context = array();
     if (isset($_POST['XSRF']) && \Kingboard\Lib\Form::getXSRFToken() == $_POST['XSRF']) {
         try {
             $pheal = new Pheal($_POST['apiuserid'], $_POST['apikey']);
             $pheal->detectAccess();
             $keyinfo = $pheal->accountScope->ApiKeyInfo();
             $keytype = $keyinfo->key->type;
             $accessmask = $keyinfo->key->accessMask;
             if (!($accessmask & 272)) {
                 throw new \Exception("Key invalid, or wrong permissions!");
             }
             if (!isset($user['keys'])) {
                 $keys = array();
             } else {
                 $keys = $user['keys'];
             }
             $keys[$_POST['apiuserid']] = array('apiuserid' => $_POST['apiuserid'], 'apikey' => $_POST['apikey'], 'type' => $keytype, 'active' => true);
             $user['keys'] = $keys;
             $user->save();
             // ensure user is refreshed in session
             \Kingboard\Lib\Auth\Auth::getUser();
         } catch (\Exception $e) {
             $context = $_POST;
             $context['error'] = $e->getMessage();
             //$context['error'] = "the key could not be validated as a valid apikey";
         }
     } elseif (isset($_POST['XSRF'])) {
         return $this->error('XSRF detected');
     }
     if (isset($user['keys'])) {
         $activeKeys = $user['keys'];
     } else {
         $activeKeys = array();
     }
     foreach ($activeKeys as $id => $key) {
         try {
             $pheal = new Pheal($key['apiuserid'], $key['apikey']);
             $chars = $pheal->accountScope->Characters()->characters->toArray();
             $charlist = array();
             foreach ($chars as $char) {
                 $charlist[] = $char['name'];
             }
             $activeKeys[$id]["chars"] = join(', ', $charlist);
         } catch (\Exception $e) {
             //print_r($e);
         }
     }
     $context = array_merge($context, array('active_keys' => $activeKeys));
     $this->render('user/index.html', $context);
 }