예제 #1
0
 public static function handlerRequest($data = NULL)
 {
     try {
         // se é uma chamada Ajax, inicializa MAjax
         if (Manager::isAjaxCall()) {
             Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
         }
         MApp::contextualize();
         self::setData($data ?: $_REQUEST);
         mtrace('DTO Data:');
         mtrace(self::getData());
         self::init();
         do {
             self::$result = MApp::handler();
         } while (self::$forward != '');
         self::terminate();
     } catch (\Maestro\Services\Exception\ENotFoundException $e) {
         self::$result = new Results\MNotFound($e);
     } catch (\Maestro\Services\Exception\ESecurityException $e) {
         self::$result = new Results\MInternalError($e);
     } catch (\Maestro\Services\Exception\ETimeOutException $e) {
         self::$result = new Results\MInternalError($e);
     } catch (\Maestro\Services\Exception\ERuntimeException $e) {
         self::$result = new Results\MRunTimeError($e);
     } catch (\Maestro\Services\Exception\EMException $e) {
         self::$result = new Results\MInternalError($e);
     } catch (\Exception $e) {
         self::$result = new Results\MInternalError($e);
     }
 }
예제 #2
0
 /**
  * Verifica se a senha fornecida por um usuário é válida 
  * utilizando autenticação challenge-response.
  * 
  * @param int $userId
  * @param string $challenge
  * @param string $response
  * @return boolean
  */
 public function authenticate($userId, $challenge, $response)
 {
     Manager::logMessage("[LOGIN] Authenticating {$userId} LdapMD5");
     $login = NULL;
     try {
         if ($this->validate($userId, $challenge, $response)) {
             $user = Manager::getModelMAD('user');
             $user->getByLogin($userId);
             $profile = $user->getProfileAtual();
             $user->getByProfile($profile);
             $login = new MLogin($user);
             if (Manager::getOptions("dbsession")) {
                 $session = Manager::getModelMAD('session');
                 $session->lastAccess($login);
                 $session->registerIn($login);
             }
             $this->setLogin($login);
             $this->setLoginLogUserId($user->getId());
             $this->setLoginLog($login->getLogin());
             Manager::logMessage("[LOGIN] Authenticated {$userId} LdapMD5");
             return true;
         }
     } catch (Exception $e) {
         Manager::logMessage("[LOGIN] {$userId} NOT Authenticated LdapMD5 - " . $e->getMessage());
     }
     Manager::logMessage("[LOGIN] {$userId} NOT Authenticated LdapMD5");
     return false;
 }
예제 #3
0
 /**
  * Define template and template variables
  */
 public function setTemplate()
 {
     $path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../templates/pages');
     $this->template = Manager::getTemplate($path);
     $this->template->context('manager', Manager::getInstance());
     $this->template->context('page', $this);
     $this->template->context('charset', Manager::getOptions('charset'));
     $this->template->context('template', $this->template);
 }
예제 #4
0
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new MKrono();
         self::$instance->baseDate = '02/01/00';
         // For day/month names
         self::$instance->localeConv = localeConv();
         self::$instance->separator = Manager::getOptions('separatorDate');
         self::$instance->formatDate = Manager::getOptions('formatDate');
         self::$instance->formatTimestamp = Manager::getOptions('formatTimestamp');
     }
     return self::$instance;
 }
예제 #5
0
 public function dispatch($action)
 {
     mtrace('mcontroller::dispatch = ' . $action);
     if (!method_exists($this, $action)) {
         mtrace('action does not exists = ' . $action);
         try {
             $this->render($action);
         } catch (\Exception $e) {
             mdump($e->getMessage() . ' ' . $e->getFile() . ' - ' . $e->getLine());
             throw new ENotFoundException(_M("App: [%s], Module: [%s], Controller: [%s] : action [%s} not found!", [$this->application, $this->module, $this->name, $action]));
         }
     } else {
         try {
             $this->action = $action;
             //if (Manager::getPage()->isPostBack()) {
             //    $actionPost = $action . 'Post';
             //    if (method_exists($this, $actionPost)) {
             //        $action = $actionPost;
             //    }
             //}
             mtrace('executing = ' . $action);
             $method = new \ReflectionMethod(get_class($this), $action);
             $params = $method->getParameters();
             $values = array();
             foreach ($params as $param) {
                 $value = $this->data->{$param->getName()};
                 if (!$value && $param->isDefaultValueAvailable()) {
                     $value = $param->getDefaultValue();
                 }
                 $values[] = $value;
             }
             $result = call_user_func_array([$this, $action], $values);
             if (!$this->getResult()) {
                 if (!Manager::isAjaxCall()) {
                     Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
                 }
                 $this->setResult(new Results\MRenderJSON(json_encode($result)));
             }
         } catch (\Exception $e) {
             mdump($e->getMessage());
             if (Manager::PROD()) {
                 $this->renderPrompt('error', $e->getMessage());
             } else {
                 $this->renderPrompt('error', "[<b>" . $this->name . '/' . $action . "</b>]" . $e->getMessage());
             }
         }
     }
 }
예제 #6
0
 public function renderJSON($json = '')
 {
     if (!Manager::isAjaxCall()) {
         Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
     }
     $ajax = Manager::getAjax();
     $ajax->setData($this->data);
     $this->setResult(new Results\MRenderJSON($json));
 }
예제 #7
0
 public function getBaseURL($absolute = false)
 {
     $url = $absolute ? $this->url->getBaseURL() : $this->url->getBasePath();
     $baseURL = str_replace('/' . Manager::getOptions('dispatcher') . '/', '', $url);
     return $baseURL;
 }
예제 #8
0
 public function __construct($datetime = NULL, $format = '')
 {
     parent::__construct($datetime, $format ?: Manager::getOptions('formatTimestamp'));
 }
예제 #9
0
 /**
  * Define template and template variables
  */
 public function setTemplate()
 {
     $path = Manager::getThemePath();
     $this->template = new MTemplate($path);
     $this->template->context('manager', Manager::getInstance());
     $this->template->context('page', $this);
     $this->template->context('charset', Manager::getOptions('charset'));
     $this->template->context('template', $this->template);
 }
예제 #10
0
 public function __construct($datetime = NULL, $format = '')
 {
     //parent::__construct();
     $this->separator = Manager::getOptions('separatorDate');
     $this->format = $format ?: Manager::getOptions('formatDate');
     $this->datetime = MKrono::getDateTime($datetime, $this->format);
 }