Exemplo n.º 1
0
 public function __construct()
 {
     $this->db = \Phpfox_Database::instance();
     $this->request = \Phpfox_Request::instance();
     if ($this->request->segment(1) == 'api') {
         \Core\Route\Controller::$isApi = true;
         if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
             throw new \Exception('Missing authentication key and pass.');
         }
         foreach ((new App())->all() as $App) {
             if ($App->auth->id == $_SERVER['PHP_AUTH_USER']) {
                 $this->active = $App;
                 break;
             }
         }
         if (!$this->active) {
             throw new \Exception('Unable to find this app.');
         }
         if ($_SERVER['PHP_AUTH_PW'] != $App->auth->key) {
             throw new \Exception('Authentication failed. Key is not valid: ' . $App->auth->key);
         }
     }
 }