Exemplo n.º 1
0
 protected function checkPermissions($action, $params)
 {
     try {
         $permissions = array();
         if (!empty($this->permissions)) {
             foreach ($this->permissions as $key => $value) {
                 if ($action === $key) {
                     $permissions = array_merge($permissions, (array) $value);
                 } elseif (substr($key, 0, 1) === '^' && $action !== substr($key, 1)) {
                     $permissions = array_merge($permissions, (array) $value);
                 } elseif (is_numeric($key)) {
                     $permissions = array_merge($permissions, (array) $value);
                 }
             }
         }
         if (!empty($permissions)) {
             Account::validate($permissions);
         }
         parent::beforeAction($action, $params);
     } catch (LoginRequiredException $e) {
         $loginUrl = array('route://admin_login', array('redirect' => \Simplify::request()->base() . \Simplify::request()->uri()));
         \Simplify::response()->redirect($loginUrl);
     } catch (SecurityException $e) {
         \Simplify::session()->warnings($e->getMessage());
         \Simplify::response()->redirect('route://admin');
     }
 }
Exemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * 
  * @see \Simplify\Controller::indexAction()
  */
 protected function indexAction()
 {
     try {
         $this->Form = new \Simplify\Form('options', __('Opções'));
         $this->Form->showMenu = false;
         $this->Form->addAction(new \Simplify\Form\Action\Config('config', __('Gerais'), \Simplify::config()->get('amp:tables:options'), 'option_name', 'option_value'));
         $this->Form->addElement(new \Simplify\Form\Element\Text('site_name', __('Nome do site')), \Simplify\Form::ACTION_CONFIG);
         $url = new \Simplify\Form\Element\Text('site_url', __('URL do site'));
         $this->Form->addElement($url, \Simplify\Form::ACTION_CONFIG);
         $this->Form->execute();
     } catch (\Simplify\ValidationException $e) {
         \Simplify::session()->warnings(__('Ocorreram erros'));
     }
     $this->set('formBody', $this->Form->render());
 }
Exemplo n.º 3
0
 /**
  * (non-PHPdoc)
  * @see \Simplify\Application::outputResponse()
  */
 protected function outputResponse($output)
 {
     if (defined('SY_IN_ADMIN') && $output instanceof \Simplify\View) {
         if (\Amplify\Install::installed() && !$output instanceof \Simplify\View\Json) {
             $output->set('user', \Amplify\Account::getUser());
             $output->set('menu', $this->menu());
             AssetManager::load('fancybox/jquery.fancybox.css', 'vendor');
             AssetManager::load('fancybox/jquery.fancybox.pack.js', 'vendor');
             AssetManager::load('amplify.js', 'app');
         }
         if (\Simplify::session()->warnings()) {
             $output->set('warnings', \Simplify::session()->warnings());
         }
         if (\Simplify::session()->notices()) {
             $output->set('notices', \Simplify::session()->notices());
         }
         \Simplify::session()->clearMessages();
     }
     return parent::outputResponse($output);
 }
Exemplo n.º 4
0
 /**
  *
  */
 protected function indexAction()
 {
     $username = '';
     $password = '';
     if (\Simplify::request()->method(\Simplify\Request::POST)) {
         try {
             $this->set('__post', true);
             $username = \Simplify::request()->post('username');
             $password = \Simplify::request()->post('password');
             \Amplify\Account::login($username, $password);
             if (\Simplify::request()->json()) {
                 return true;
             }
             $url = \Simplify::request()->get('redirect', 'route://admin');
             return \Simplify::response()->redirect($url);
         } catch (\Amplify\LoginException $e) {
             \Simplify::session()->warnings($e->getMessage());
         }
     }
     $this->set('username', $username);
     $this->set('password', $password);
 }
Exemplo n.º 5
0
 protected function indexAction()
 {
     $username = '';
     $email = '';
     $password = '';
     if (\Simplify::request()->method(\Simplify\Request::POST)) {
         try {
             $username = \Simplify::request()->post('username');
             $email = \Simplify::request()->post('email');
             $password = \Simplify::request()->post('password');
             \Amplify\Install::performInstall($username, $email, $password);
             \Simplify::session()->notices(__('Instalação realizada com sucesso.'));
             $url = \Simplify::request()->get('redirect', \Simplify::router()->make('admin'));
             \Simplify::response()->redirect($url);
         } catch (\Simplify\ValidationException $e) {
             \Simplify::session()->warnings($e->getErrors());
         }
     }
     $this->set('username', $username);
     $this->set('email', $email);
     $this->set('password', $password);
 }
Exemplo n.º 6
0
 /**
  * 
  */
 protected function initialize()
 {
     \Simplify::session()->start();
 }
Exemplo n.º 7
0
 /**
  *
  * @param array $user            
  * @return void
  */
 public static function authenticate($user)
 {
     $token = self::generateAccessToken($user);
     \Simplify::session()->set('token', $token);
     self::setUser($user);
     self::loadUserAcl($user);
 }
Exemplo n.º 8
0
 public function onBeforeDelete(\Simplify\Form\Action $action, $row)
 {
     if (sy_get_param($row, Form::ID) == 1) {
         \Simplify::session()->warnings(__('Não é possível remover este usuário'));
         \Simplify::response()->redirect($this->Form->url()->extend()->set('formAction', null));
     }
 }
Exemplo n.º 9
0
 /**
  * (non-PHPdoc)
  *
  * @see \Simplify\Controller::indexAction()
  */
 protected function indexAction()
 {
     try {
         $result = $this->Form->execute();
         if ($result == \Simplify\Form::RESULT_SUCCESS) {
             \Simplify::session()->notices('Success');
             return \Simplify::response()->redirect($this->Form->url()->extend()->set('formAction', null));
         }
     } catch (\Simplify\ValidationException $e) {
         \Simplify::session()->warnings(__('Verifique os erros abaixo'));
         $errors = (array) $e->getErrors();
         foreach ($errors as $key => $errors) {
             if (is_int($key)) {
                 \Simplify::session()->warnings($errors);
             }
         }
     } catch (\Exception $e) {
         \Simplify::session()->warnings($e->getMessage());
     }
     $this->set('formBody', $this->Form->render());
 }
Exemplo n.º 10
0
 public static function getActiveModules()
 {
     if (self::$modules === false) {
         self::$modules = array();
         $modules = \Amplify\Options::value('amp_active_modules', array());
         foreach ($modules as &$path) {
             /*
              * $class = substr($path, ($p = strrpos($path, '/')) === false ? 0 : $p + 1, -4);
              *
              * $filename = \Simplify::config()->get('app_dir') . 'modules' . $path;
              *
              * if (!file_exists($filename)) {
              * \Simplify::session()->warnings("Could not load module: file not found: <b>{$path}</b>");
              * }
              * else {
              * require_once ($filename);
              *
              * if (!class_exists($class)) {
              * \Simplify::session()->warnings("Could not load module: class not found: <b>{$class}</b>");
              * }
              * elseif (!is_subclass_of($class, '\Amplify\Module')) {
              * \Simplify::session()->warnings("Could not load module: <b>{$class}</b> is not a subclass of \Amplify\Module");
              * }
              * else {
              * self::$modules[$path] = new $class();
              * }
              * }
              */
             $class = $path;
             if (!class_exists($class)) {
                 self::deactivateModule($path);
                 \Simplify::session()->warnings("Could not load module: class not found: <b>{$class}</b>");
             } elseif (!is_subclass_of($class, '\\Amplify\\Module')) {
                 self::deactivateModule($path);
                 \Simplify::session()->warnings("Could not load module: <b>{$class}</b> is not a subclass of \\Amplify\\Module");
             } else {
                 self::$modules[$path] = new $class();
             }
         }
     }
     return self::$modules;
 }
Exemplo n.º 11
0
 /**
  * (non-PHPdoc)
  *
  * @see \Simplify\Controller::indexAction()
  */
 protected function indexAction()
 {
     try {
         $this->Form->execute();
     } catch (\Simplify\ValidationException $e) {
         \Simplify::session()->warnings(__('Ocorreram erros'));
     }
     $this->set('formBody', $this->Form->render());
 }