/**
  * discover all available services
  */
 public function discover()
 {
     $services = array();
     $service_list = (require Path::getConfigDir() . '/services.php');
     foreach ($service_list as $service_name => $service_options) {
         foreach ($service_options['groups'] as $group) {
             if (User::get()->isAuthorized($group)) {
                 $services[$service_name] = $service_options['description'];
                 break;
             }
         }
     }
     return $services;
 }
 public function __call($method, $args)
 {
     if (count($args) == 0) {
         throw new AuthenticationError('This service needs authentication');
     }
     $token = array_shift($args);
     $token_bits = explode(':', $token);
     if (count($token_bits) != 2) {
         throw new AuthenticationError('Incorrect user credentials');
     }
     User::login($token_bits[0], $token_bits[1]);
     if ($this->group_name && !User::get()->isAuthorized($this->group_name)) {
         throw new AuthenticationError('You are not authorized to run this method');
     }
     return @call_user_func_array(array($this->getInnerService(), $method), $args);
 }
 public function login($user, $password)
 {
     $password = password_hash($password, PASSWORD_DEFAULT);
     User::login($user, $password);
     return array('token' => "{$user}:{$password}");
 }