diff --git a/.idea/safekat.iml b/.idea/safekat.iml index c956989b..91d27d36 100755 --- a/.idea/safekat.iml +++ b/.idea/safekat.iml @@ -1,7 +1,11 @@ - + + + + + diff --git a/ci4/app/Config/RBAC/permissionMatrix.php b/ci4/app/Config/RBAC/permissionMatrix.php index f160f72b..8dc1c381 100644 --- a/ci4/app/Config/RBAC/permissionMatrix.php +++ b/ci4/app/Config/RBAC/permissionMatrix.php @@ -47,15 +47,14 @@ const SK_PERMISSION_MATRIX = [ "actividad.menu", ], "cliente" => [ - "token.token", - "token.menu", - "Profile.index", - "Profile.store", - "Profile.menu", - "Activity.index", - "Activity.menu", - "save.save", - "save.menu", + "clientes.create", + "clientes.edit", + "clientes.delete", + "clientes.menu", + "presupuesto.create", + "presupuesto.edit", + "presupuesto.delete", + "presupuesto.menu", ], "comercial" => [ "token.token", diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 4e223770..45e27602 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -11,7 +11,7 @@ service('auth')->routes($routes); //WEB ROUTER ------------------------------------------------------ //------------------------------------------------------------------ -$routes->get('/', 'Home::index'); +$routes->get('/', 'Home::index', ['as' => 'home']); $routes->get('lang/{locale}', 'Language::index'); $routes->get('viewmode/(:alpha)', 'Viewmode::index/$1'); @@ -334,7 +334,29 @@ $routes->group('provincias', ['namespace' => 'App\Controllers\Configuracion'], f $routes->resource('provincias', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Provincias', 'except' => 'show,new,create,update']); -$routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { +/* Rutas para configuraciones */ +$routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { + + /* Cliente */ + $routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { + $routes->get('', 'Cliente::index', ['as' => 'clienteList']); + $routes->match(['get', 'post'], 'add', 'Cliente::add', ['as' => 'clienteAdd']); + $routes->match(['get', 'post'], 'edit/(:num)', 'Cliente::edit/$1', ['as' => 'clienteEdit']); + $routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'clienteDelete']); + $routes->post('datatable', 'Cliente::datatable', ['as' => 'clienteDT']); + }); + + /* Precios */ + /*$routes->group('precios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { + $routes->post('datatable', 'ClientePrecios::datatable', ['as' => 'clientePreciosDT']); + $routes->post('datatable_editor', 'ClientePrecios::datatable_editor', ['as' => 'clientePreciosDTE']); + });*/ + + +}); + + +/*$routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->get('', 'Cliente::index', ['as' => 'clienteList']); $routes->get('add', 'Cliente::add', ['as' => 'newCliente']); $routes->post('add', 'Cliente::add', ['as' => 'createCliente']); @@ -346,15 +368,15 @@ $routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function $routes->post('allmenuitems', 'Cliente::allItemsSelect', ['as' => 'select2ItemsOfClientes']); $routes->post('menuitems', 'Cliente::menuItems', ['as' => 'menuItemsOfClientes']); }); -$routes->resource('cliente', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Cliente', 'except' => 'show,new,create,update']); +$routes->resource('cliente', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Cliente', 'except' => 'show,new,create,update']);*/ $routes->group('clienteprecios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->post('datatable', 'Clienteprecios::datatable', ['as' => 'dataTableOfClienteprecios']); $routes->post('datatable_editor', 'Clienteprecios::datatable_editor', ['as' => 'editorOfClienteprecios']); }); - $routes->resource('clienteprecios', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clienteprecios', 'except' => 'show,new,create,update']); + $routes->group('clienteplantillaprecios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->get('', 'Clienteplantillaprecios::index', ['as' => 'clienteplantillapreciosList']); $routes->get('add', 'Clienteplantillaprecios::add', ['as' => 'newClienteplantillaprecios']); diff --git a/ci4/app/Controllers/Catalogo/Catalogo.php b/ci4/app/Controllers/Catalogo/Catalogo.php deleted file mode 100755 index 2e0d71b3..00000000 --- a/ci4/app/Controllers/Catalogo/Catalogo.php +++ /dev/null @@ -1,40 +0,0 @@ -viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null); $this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null); - $this->viewData['formAction'] = site_url('cliente/add'); // route_to('createCliente'); IMN + $this->viewData['formAction'] = route_to('clienteAdd'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Clientes.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix'); @@ -227,7 +227,7 @@ class Cliente extends \App\Controllers\BaseResourceController $this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null); $this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null); - $this->viewData['formAction'] = route_to('updateCliente', $id); + $this->viewData['formAction'] = route_to('clienteEdit', $id); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Clientes.moduleTitle') . ' ' . lang('Basic.global.edit3'); @@ -355,10 +355,10 @@ class Cliente extends \App\Controllers\BaseResourceController protected function getUserListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; - if (!empty($selId)) : - $userModel = model('App\Models\Usuarios\UserModel'); + if (!is_null($selId)) : + $userModel = model('App\Models\UserModel'); - $selOption = $userModel->where('id_user', $selId)->findColumn('first_name'); + $selOption = $userModel->where('id', $selId)->findColumn('first_name'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; @@ -370,7 +370,7 @@ class Cliente extends \App\Controllers\BaseResourceController protected function getComunidadAutonomaListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])]; - if (!empty($selId)) : + if (!is_null($selId)) : $comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel'); $selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre'); @@ -385,10 +385,10 @@ class Cliente extends \App\Controllers\BaseResourceController protected function getUserListItems2($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; - if (!empty($selId)) : - $userModel = model('App\Models\Configuracion\UserModel'); + if (!is_null($selId)) : + $userModel = model('App\Models\UserModel'); - $selOption = $userModel->where('id_user', $selId)->findColumn('last_name'); + $selOption = $userModel->where('id', $selId)->findColumn('last_name'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; diff --git a/ci4/app/Controllers/Clientes/Clienteprecios.php b/ci4/app/Controllers/Clientes/ClientePrecios.php similarity index 100% rename from ci4/app/Controllers/Clientes/Clienteprecios.php rename to ci4/app/Controllers/Clientes/ClientePrecios.php diff --git a/ci4/app/Controllers/Configuracion/Group.php b/ci4/app/Controllers/Configuracion/Group.php index 355a5fe2..0ba2fb80 100755 --- a/ci4/app/Controllers/Configuracion/Group.php +++ b/ci4/app/Controllers/Configuracion/Group.php @@ -189,6 +189,12 @@ class Group extends \App\Controllers\GoBaseController endif; if ($noException && $successfulResult) : + + // IMN hacer las configuraciones hard coded + helper('rbac'); + generate_php_roles_constant(); + generate_php_permissions_matrix_constant(); + $id = $groupEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index 36564178..c49c0e22 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -4,8 +4,10 @@ use App\Entities\Usuarios\UserEntity; use App\Models\Usuarios\GroupModel; -use App\Models\Usuarios\GroupsUsersModel; + use App\Models\UserModel; +use App\Models\Usuarios\GroupsUsersModel; +use CodeIgniter\Shield\Entities\User; class Users extends \App\Controllers\GoBaseController { @@ -43,49 +45,40 @@ class Users extends \App\Controllers\GoBaseController { public function index() { $this->viewData['usingClientSideDataTable'] = true; - $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]); - $this->viewData['user_model'] = $this->user_model; parent::index(); } - public function add() { - - + public function add() { if ($this->request->getPost()) : - $nullIfEmpty = true; // !(phpversion() >= '8.1'); - $postData = $this->request->getPost(); - - if(!empty($postData['password'])){ - $phpass = new PasswordHash(8, true); - $postData['password'] = $phpass->HashPassword($this->request->getPost('password')); - } - - + $currentGroups = $postData['group']??[]; unset($postData['group']); - $sanitizedData = $this->sanitized($postData, $nullIfEmpty); - - if ($this->request->getPost('last_ip') == null ) { - $sanitizedData['last_ip'] = '::1'; - } - - $sanitizedData['token'] = md5(uniqid(rand(), true)); + $sanitizedData = $this->sanitized($postData, true); $noException = true; + + $users = auth()->getProvider(); + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : - if ($this->canValidate()) : try { - $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); + + $user = new User([ + 'username' => strstr($sanitizedData['email'], '@', true), + 'email' => $sanitizedData['email'], + 'password' => 'Safekat2024', + ]); + $users->save($user); + $successfulResult = true; // Hacked } catch (\Exception $e) { $noException = false; $this->dealWithException($e); @@ -99,11 +92,12 @@ class Users extends \App\Controllers\GoBaseController { endif; if ($noException && $successfulResult) : - $id = $this->model->db->insertID(); + $id = $users->getInsertID(); + $this->group_user_model->where('user_id', $user->id)->delete(); foreach($currentGroups as $group){ $group_user_data = [ - 'token_user' => $sanitizedData['token'], - 'token_group' => $group + 'user_id' => $user->id, + 'group' => $group ]; $this->group_user_model->insert($group_user_data); } @@ -127,11 +121,8 @@ class Users extends \App\Controllers\GoBaseController { endif; // ($requestMethod === 'post') $this->viewData['user'] = isset($sanitizedData) ? new UserEntity($sanitizedData) : new UserEntity(); - $this->viewData['paisList'] = $this->getPaisListItems(); - $this->viewData['formAction'] = route_to('createUser'); - $this->viewData['groups'] = $this->group_model->select('token,title')->findAll(); - + $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); $this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix'); @@ -143,6 +134,7 @@ class Users extends \App\Controllers\GoBaseController { if ($requestedId == null) : return $this->redirect2listView(); endif; + $id = filter_var($requestedId, FILTER_SANITIZE_URL); $user = $this->model->find($id); @@ -150,37 +142,22 @@ class Users extends \App\Controllers\GoBaseController { $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Users.user')), $id]); return $this->redirect2listView('errorMessage', $message); endif; - if ($this->request->getPost()) : - $nullIfEmpty = true; // !(phpversion() >= '8.1'); - $postData = $this->request->getPost(); + $currentGroups = $postData['group']; unset($postData['group']); + $sanitizedData = $this->sanitized($postData, true); - if(!empty($postData['password'])){ - $phpass = new PasswordHash(8, true); - $postData['password'] = $phpass->HashPassword($this->request->getPost('password')); - } - - $sanitizedData = $this->sanitized($postData, $nullIfEmpty); - if ($this->request->getPost('tfa') == null ) { - $sanitizedData['tfa'] = false; - } - if ($this->request->getPost('blocked') == null ) { - $sanitizedData['blocked'] = false; - } - if ($this->request->getPost('last_ip') == null ) { - $sanitizedData['last_ip'] = '::1'; + if ($this->request->getPost('status') == 0 ) { + $sanitizedData['status'] = null; } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : - - if ($this->canValidate()) : try { @@ -196,22 +173,21 @@ class Users extends \App\Controllers\GoBaseController { endif; $user->fill($sanitizedData); - $thenRedirect = false; + endif; if ($noException && $successfulResult) : - $postData = $this->request->getPost(); - - $this->group_user_model->where('token_user', $user->token)->delete(); + + $this->group_user_model->where('user_id', $user->id)->delete(); foreach($currentGroups as $group){ $group_user_data = [ - 'token_user' => $user->token, - 'token_group' => $group + 'user_id' => $user->id, + 'group' => $group ]; $this->group_user_model->insert($group_user_data); } - $id = $user->id_user ?? $id; + $id = $user->id ?? $id; $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Users.user'))]) . 'Downloads'; $message .= anchor(route_to('editUser', $id), lang('Basic.global.continueEditing').'?'); $message = ucfirst(str_replace("'", "\'", $message)); @@ -230,18 +206,38 @@ class Users extends \App\Controllers\GoBaseController { endif; // ($requestMethod === 'post') $this->viewData['user'] = $user; - $this->viewData['paisList'] = $this->getPaisListItems(); - $this->viewData['formAction'] = route_to('updateUser', $id); - - $this->viewData['selectedGroups'] = $this->group_user_model->select('token_group')->where('token_user', $user->token)->findAll(); - $this->viewData['groups'] = $this->group_model->select('token,title')->findAll(); - + $this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId); + $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); $this->viewData['boxTitle'] = lang('Basic.global.edit2') .lang('Users.user').' '.lang('Basic.global.edit3'); - - + return $this->displayForm(__METHOD__, $id); } // end function edit(...) + + + public function delete($requestedId = null, bool $deletePermanently = true) { + + if ($requestedId == null) : + return $this->redirect2listView(); + endif; + + $id = filter_var($requestedId, FILTER_SANITIZE_URL); + $user = $this->model->find($id); + + if ($user == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Users.user')), $id]); + return $this->redirect2listView('errorMessage', $message); + endif; + + $users = auth()->getProvider(); + $users->delete($user->id, $deletePermanently); + + $message = "Usuario eliminado correctamente"; + return $this->redirect2listView('successMessage', $message); + + + + } // end function delete(...) diff --git a/ci4/app/Controllers/Envioslogistica/Logistica.php b/ci4/app/Controllers/Envioslogistica/Logistica.php deleted file mode 100755 index b6a7a9d5..00000000 --- a/ci4/app/Controllers/Envioslogistica/Logistica.php +++ /dev/null @@ -1,32 +0,0 @@ -user_model = new UserModel(); - $this->activity_model = new ActivityModel(); } public function index() diff --git a/ci4/app/Controllers/Importacion/Importar.php b/ci4/app/Controllers/Importacion/Importar.php deleted file mode 100755 index 1f48b9aa..00000000 --- a/ci4/app/Controllers/Importacion/Importar.php +++ /dev/null @@ -1,36 +0,0 @@ -to('profile'); } - public function notification() - { - $session = session(); - $data['title'] = [ - 'module' => lang("App.notification_title_my"), - 'page' => lang("App.notification_subtitle_my"), - 'icon' => 'fas fa-bell' - ]; - $data['breadcrumb'] = [ - ['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false], - ['title' => lang("App.notification_title_my"), 'route' => "", 'active' => true] - ]; - - $data['btn_add'] = [ - 'title' => lang("App.notification_btn_add"), - 'route' => '/notification/add', - 'class' => 'btn btn-lg btn-primary float-md-right', - 'icon' => 'fas fa-plus' - ]; - - echo view(getenv('theme.path').'main/header'); - echo view(getenv('theme.path').'form/my/notification',$data); - echo view(getenv('theme.path').'main/footer'); - } - - public function notification_view($id) - { - $session = session(); - $data['obj'] = $this->notification_model->where('token', $id)->first(); - if($data['obj']==null){ - return redirect()->to('/my/notification'); - }else{ - if(!$data['obj']['is_read']){ - $this->notification_model->save(['id_notification' => $data['obj']['id_notification'],'is_read' => true]); - $notification = $session->get('notification')??[]; - foreach ($notification as $key => $value){ - if($notification[$key]['token'] == $id){ - $notification[$key]['is_read'] = '1'; - } - } - $pulse = $this->notification_model->where('user_recipient',$session->get('token'))->where('is_read',false)->countAllResults() ?? 0; - $session->set('pulse', $pulse); - $session->set('notification',$notification); - } - } - - $data['title'] = [ - 'module' => lang("App.notification_title_my"), - 'page' => lang("App.notification_subtitle_view"), - 'icon' => 'far fa-envelope-open' - ]; - - $data['breadcrumb'] = [ - ['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false], - ['title' => lang("App.notification_title_my"), 'route' => "/my/notification", 'active' => false], - ['title' => lang("App.notification_subtitle_view"), 'route' => "", 'active' => true] - ]; - - $data['btn_return'] = [ - 'title' => lang("App.global_come_back"), - 'route' => '/my/notification', - 'class' => 'btn btn-dark mr-1', - 'icon' => 'fas fa-angle-left' - ]; - - echo view(getenv('theme.path').'main/header'); - echo view(getenv('theme.path').'form/my/view',$data); - echo view(getenv('theme.path').'main/footer'); - } } diff --git a/ci4/app/Controllers/Servicios/Compras.php b/ci4/app/Controllers/Servicios/Compras.php deleted file mode 100755 index 27536b8f..00000000 --- a/ci4/app/Controllers/Servicios/Compras.php +++ /dev/null @@ -1,26 +0,0 @@ -user()->can('plantilla-tarifa.menu')); + //$user = auth()->user(); + generate_php_permissions_constant(); //echo generate_php_permissions_matrix_constant(); diff --git a/ci4/app/Entities/Usuarios/GroupsUsersEntity.php b/ci4/app/Entities/Usuarios/GroupsUsersEntity.php new file mode 100644 index 00000000..499fb298 --- /dev/null +++ b/ci4/app/Entities/Usuarios/GroupsUsersEntity.php @@ -0,0 +1,17 @@ + null, + "user_id" => null, + "group" => null, + "created_at" => null + ]; + protected $casts = [ + + ]; +} diff --git a/ci4/app/Entities/Usuarios/UsersEntity.php b/ci4/app/Entities/Usuarios/UsersEntity.php new file mode 100644 index 00000000..7ff93bb7 --- /dev/null +++ b/ci4/app/Entities/Usuarios/UsersEntity.php @@ -0,0 +1,16 @@ + null, + "last_name" => null + ]; + protected $casts = [ + + ]; +} diff --git a/ci4/app/Models/Clientes/ClienteUsuariosModel.php b/ci4/app/Models/Clientes/ClienteUsuariosModel.php index 948cee51..474b6ce3 100644 --- a/ci4/app/Models/Clientes/ClienteUsuariosModel.php +++ b/ci4/app/Models/Clientes/ClienteUsuariosModel.php @@ -2,9 +2,11 @@ namespace App\Models\Clientes; -class ClienteUsuariosModel extends \App\Models\BaseModel +use CodeIgniter\Shield\Models\UserModel as ShieldUserModel; + +class ClienteUsuariosModel extends ShieldUserModel { - protected $table = "auth_user"; + protected $table = "users"; /** * Whether primary key uses auto increment. @@ -16,11 +18,11 @@ class ClienteUsuariosModel extends \App\Models\BaseModel const SORTABLE = [ 0 => "t1.first_name", 1 => "t1.last_name", - 2 => "t1.email", + 2 => "t2.secret", ]; protected $allowedFields = ["id", "first_name", "last_name", "email"]; - protected $returnType = "App\Entities\Usuarios\UserEntity"; + protected $returnType = "App\Entities\Usuarios\UsersEntity"; protected $useTimestamps = true; protected $useSoftDeletes = false; @@ -93,10 +95,12 @@ class ClienteUsuariosModel extends \App\Models\BaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id_user AS id, t1.first_name AS nombre, t1.last_name AS apellidos, t1.email AS email" + "t1.id AS id, t1.first_name AS nombre, t1.last_name AS apellidos, + t2.secret AS email" ); - $builder->where('t1.id_user', $cliente_id); + $builder->join("auth_identities t2", "t1.id = t2.user_id", "left"); + $builder->where('t1.id', $cliente_id); return empty($search) ? $builder @@ -104,7 +108,7 @@ class ClienteUsuariosModel extends \App\Models\BaseModel ->groupStart() ->like("t1.first_name", $search) ->orLike("t1.last_name", $search) - ->orLike("t1.email", $search) + ->orLike("t2.secret", $search) ->groupEnd(); } } diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php index bd001e74..96d2ca92 100644 --- a/ci4/app/Models/UserModel.php +++ b/ci4/app/Models/UserModel.php @@ -18,4 +18,12 @@ class UserModel extends ShieldUserModel 'last_name', // Añadido ]; } + + /*protected $validationRules = [ + "email" => [ + "label" => "RolesPermisos.email", + "rules" => "required|max_length[150]", + ] + + ];*/ } diff --git a/ci4/app/Models/Usuarios/GroupModel.php b/ci4/app/Models/Usuarios/GroupModel.php index b7c34473..704d0535 100644 --- a/ci4/app/Models/Usuarios/GroupModel.php +++ b/ci4/app/Models/Usuarios/GroupModel.php @@ -100,6 +100,18 @@ class GroupModel extends \App\Models\BaseModel ->countAllResults(); } + + public function getUsersRoles($userId) + { + + return $this->db + ->table('auth_groups_users') + ->select('group') + ->where('user_id', $userId) + ->get() + ->getResult(); + } + public function getRolPermissionList($rolId) { $rolRecord = $this->find($rolId); diff --git a/ci4/app/Models/Usuarios/GroupsUsersModel.php b/ci4/app/Models/Usuarios/GroupsUsersModel.php new file mode 100644 index 00000000..03a7ad99 --- /dev/null +++ b/ci4/app/Models/Usuarios/GroupsUsersModel.php @@ -0,0 +1,23 @@ + - +