Пример #1
0
 /**
  * @inheritdoc
  */
 public function exec(Server $server, ConnectionInterface $db, CacheInterface $cache)
 {
     $operations = array();
     foreach ($server->config('application.operations') as $path => $op) {
         /* @var \Rocker\REST\OperationInterface $operation */
         $operation = new $op(null);
         $operations[] = array('class' => $op, 'methods' => implode(',', $operation->allowedMethods()), 'path' => $path);
     }
     return new OperationResponse(200, $operations);
 }
Пример #2
0
 /**
  * @param $data
  * @param Server $server
  * @return \Rocker\Object\User\UserInterface|null
  */
 public function rc4Auth($data, $server)
 {
     $conf = $server->config('application.auth');
     $parts = explode(':', RC4Cipher::decrypt($conf['secret'], base64_decode($data)));
     if (count($parts) == 2 && !is_numeric($parts[0])) {
         // don't allow to login using user id
         $user = $this->userFactory->load($parts[0]);
         if ($user !== null && $user->hasPassword($parts[1])) {
             return $user;
         }
     }
     return null;
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function exec(Server $server, ConnectionInterface $db, CacheInterface $cache)
 {
     // add possible config
     $this->setConfig($server->config('application.user_object'));
     // Create user factory
     if (empty($this->conf['factory'])) {
         $this->userFactory = new UserFactory($db, $cache);
     } else {
         $this->userFactory = new $this->conf['factory']($db, $cache);
     }
     $method = $this->request->getMethod();
     $requestedUser = $this->requestedObject() ? $this->userFactory->load($this->requestedObject()) : false;
     if (($method == 'POST' || $method == 'DELETE') && $requestedUser && !$this->user->isAdmin() && !$this->user->isEqual($requestedUser)) {
         return new OperationResponse(401, array('error' => 'Only admins can edit/remove other users'));
     }
     if ($method == 'DELETE' && $requestedUser && $requestedUser->isAdmin()) {
         return new OperationResponse(403, array('error' => 'A user with admin privileges can not be removed. You have to remove admin privileges first (/api/admin)'));
     }
     // Trigger event
     $server->triggerEvent(strtolower($method) . '.user', $db, $cache);
     return parent::exec($server, $db, $cache);
 }
Пример #4
0
 /**
  * @param Server $server
  * @param ConnectionInterface $db
  * @param \Rocker\Cache\CacheInterface $cache
  * @return array
  */
 public static function deleteUserEvent($server, $db, $cache)
 {
     $userFactory = new UserFactory($db, $cache);
     $user = $userFactory->load(basename($server->request()->getPath()));
     if ($user !== null && ($files = $user->meta()->get('files', array()))) {
         $storage = self::loadStorageClass($server);
         self::deleteAllFiles($user, $userFactory, $files, $storage);
     }
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function exec(Server $server, ConnectionInterface $db, CacheInterface $cache)
 {
     $userData = $server->applyFilter('user.array', $this->user->toArray(), $db, $cache);
     return new OperationResponse(200, $userData);
 }
Пример #6
0
 /**
  * @param OperationInterface $op
  * @return bool
  */
 private function authenticate(OperationInterface $op, Server $server)
 {
     /* @var AuthenticatorInterface $authenticator */
     $authConfig = $this->server->config('application.auth');
     $authenticator = new $authConfig['class']();
     $user = $authenticator->auth($this->server, $this->db, $this->cache);
     if (empty($user) || $op->requiresAdminAuth() && !$user->isAdmin()) {
         return false;
     }
     $op->setAuthenticatedUser($user);
     $server->setAuthenticatedUser($user);
     return true;
 }
 /**
  * @param ObjectInterface $object
  * @param \Rocker\Server $server
  * @param ConnectionInterface $db
  * @param CacheInterface $cache
  * @return mixed
  */
 protected function objectToArray($object, $server, $db, $cache)
 {
     return $server->applyFilter('object.array', $object->toArray(), $db, $cache);
 }