/**
  * Define os parâmetros do mecanismo MVC
  * @return object Retorna o objeto com as propriedades definidas
  */
 public function initialize($baseURI, $controller_directory)
 {
     if (!empty($baseURI) && !empty($controller_directory)) {
         $explode = array_values(array_filter(explode('/', $_SERVER['REQUEST_URI'])));
         if (isset($explode[0]) && $explode[0] == str_replace('/', '', $baseURI)) {
             unset($explode[0]);
             $explode = array_values($explode);
         }
         if (count($explode) == 0) {
             return $this;
         }
         if (file_exists($controller_directory . $explode[0])) {
             $this->subfolder = $explode[0] . DS;
             if (isset($explode[1])) {
                 $this->controller = Tools::filteredName($explode[1]) . 'Controller';
             }
             if (isset($explode[2])) {
                 $this->action = lcfirst(Tools::filteredName($explode[2])) . 'Action';
                 unset($explode[2]);
             }
         } elseif (count($explode) == 1) {
             $this->controller = Tools::filteredName($explode[0]) . 'Controller';
             return $this;
         } else {
             $this->controller = Tools::filteredName($explode[0]) . 'Controller';
             $this->action = lcfirst(Tools::filteredName($explode[1])) . 'Action';
         }
         unset($explode[0], $explode[1]);
         $this->params = array_values($explode);
     }
 }
 public static function cadastrar(array $post)
 {
     $callbackObj = new \stdClass();
     $callbackObj->user = null;
     $callbackObj->status = false;
     $callbackObj->errors = array();
     $role = Role::find_by_role('user');
     if (is_null($role)) {
         array_push($callbackObj->errors, 'A role user não existe. Contate o administrador');
         return $callbackObj;
     }
     $user_data = array('role_id' => $role->id, 'status' => 1);
     $password = \HXPHP\System\Tools::hashHX($post['password']);
     $post = array_merge($post, $user_data, $password);
     $cadastrar = self::create($post);
     if ($cadastrar->is_valid()) {
         $callbackObj->user = $cadastrar;
         $callbackObj->status = true;
         return $callbackObj;
     }
     $errors = $cadastrar->errors->get_raw_errors();
     foreach ($errors as $field => $message) {
         array_push($callbackObj->errors, $message[0]);
     }
     return $callbackObj;
 }
Example #3
0
File: User.php Project: ldapunt/tbr
 public static function cadastrar(array $post)
 {
     $role = Role::find_by_role('user');
     $post = array_merge($post, array('role_id' => $role->id, 'status' => 1));
     $password = \HXPHP\System\Tools::hashHX($post['password']);
     $post = array_merge($post, $password);
     return self::create($post);
 }
 public function loadModules($obj)
 {
     foreach ($this->modules as $module) {
         $module_class = Tools::filteredName(ucwords($module));
         $object = 'HXPHP\\System\\Configs\\Modules\\' . $module_class;
         if (!class_exists($object)) {
             throw new \Exception("O modulo <'{$object}'> informado nao existe.", 1);
         } else {
             $obj->{$module} = new $object();
         }
     }
     return $obj;
 }
 public function add($environment = null)
 {
     if ($environment == null) {
         $environment = $this->defaultEnvironment;
     }
     $name = strtolower(Tools::filteredName($environment));
     $object = 'HXPHP\\System\\Configs\\Environments\\Environment' . ucfirst(Tools::filteredName($environment));
     if (!class_exists($object)) {
         throw new \Exception('O ambiente informado nao esta definido nas configuracoes do sistema.');
     } else {
         $this->{$name} = new $object();
         return $this->{$name};
     }
 }
Example #6
0
 public static function start_processing(array $data, LoginController $ctrlLogin)
 {
     $callbackObj = new \stdClass();
     $callbackObj->user = null;
     $callbackObj->status = false;
     $callbackObj->error = null;
     $callbackObj->errors = array();
     $callbackObj = self::validateData($data, $callbackObj);
     if ($callbackObj->error) {
         return $callbackObj;
     }
     $user = User::find_by_username($data['username']);
     if (!is_null($user)) {
         $callbackObj->user = $user;
         $hash = \HXPHP\System\Tools::hashHX($data['password'], $user->salt);
         if ($user->password === $hash['password']) {
             $callbackObj->status = true;
         }
         $attempt_access = self::check_latest_attempt_to_access($callbackObj->user->id);
         if ($attempt_access < self::$minTime - 1) {
             $min = self::$minTime - 1;
             $callbackObj->error = true;
             array_push($callbackObj->errors, ['danger', '<p class="text-center"> Seu login foi bloqueado por motivos de segurança. </p>', '<p class="text-center"> Aguarde ' . ($min - $attempt_access) . ' minuto(s) e tente novamente. </p>']);
             $ctrlLogin->session->set('attemptAccess', 0);
             return $callbackObj;
         }
         var_dump($ctrlLogin->session->get('attemptAccess'));
         if ($ctrlLogin->session->get('attemptAccess') > self::$maxAttempt) {
             self::register_access_attempt($callbackObj->user->id);
             $ctrlLogin->session->set('attemptAccess', 0);
         }
         if ($callbackObj->status === false) {
             $attempt = $ctrlLogin->session->get('attemptAccess');
             $attempt++;
             $ctrlLogin->session->set('attemptAccess', $attempt);
         } else {
             return $callbackObj;
         }
     }
     $callbackObj->error = true;
     array_push($callbackObj->errors, self::$message['error_user_or_password']);
     return $callbackObj;
 }
 /**
  * Define os parâmetros do mecanismo MVC
  * @return object Retorna o objeto com as propriedades definidas
  */
 public function initialize($baseURI)
 {
     if (!empty($baseURI)) {
         $explode = array_values(array_filter(explode('/', $_SERVER['REQUEST_URI'])));
         if (isset($explode[0]) && $explode[0] == str_replace('/', '', $baseURI)) {
             unset($explode[0]);
             $explode = array_values($explode);
         }
         if (count($explode) == 0) {
             $this->controller = 'IndexController';
             $this->action = 'indexAction';
             return $this;
         }
         if (count($explode) == 1) {
             $this->controller = Tools::filteredName($explode[0]) . 'Controller';
             $this->action = 'indexAction';
             return $this;
         }
         $this->controller = Tools::filteredName($explode[0]) . 'Controller';
         $this->action = lcfirst(Tools::filteredName($explode[1])) . 'Action';
         unset($explode[0], $explode[1]);
         $this->params = array_values($explode);
     }
 }
 /**
  * Carrega serviços, módulos e helpers
  * @param  string $object Nome da classe
  * @param  string|array  $params Parâmetros do método construtor
  * @return object         Objeto injetado
  */
 public function load()
 {
     $total_args = func_num_args();
     if (!$total_args) {
         throw new \Exception("Nenhum objeto foi definido para ser carregado.", 1);
     }
     /**
      * Retorna todos os argumentos e define o primeiro como
      * o objeto que será injetado
      * @var array
      */
     $args = func_get_args();
     $object = $args[0];
     /**
      * Define os demais argumentos passados como
      * parâmetros para o construtor do objeto injetado
      */
     unset($args[0]);
     $params = !$args ? [] : array_values($args);
     /**
      * Tratamento que adiciona a pasta do módulo
      */
     $explode = explode('\\', $object);
     $object = $object . '\\' . end($explode);
     $object = 'HXPHP\\System\\' . $object;
     if (class_exists($object)) {
         $name = end($explode);
         $name = strtolower(Tools::filteredName($name));
         if ($params) {
             $ref = new \ReflectionClass($object);
             $this->view->{$name} = $ref->newInstanceArgs($params);
         } else {
             $this->view->{$name} = new $object();
         }
         return $this->view->{$name};
     }
 }
 public static function atualizarSenha($user, $newPassword)
 {
     $user = self::find_by_id($user->id);
     $password = \HXPHP\System\Tools::hashHX($newPassword);
     $user->password = $password['password'];
     $user->salt = $password['salt'];
     return $user->save(false);
 }