From 159c4a6ce154485b7d8b4de4e62deb5d24f831cd Mon Sep 17 00:00:00 2001 From: imnavajas Date: Mon, 15 Jul 2024 15:26:53 +0200 Subject: [PATCH 1/4] =?UTF-8?q?a=C3=B1adido=20opcion=20de=20crear=20contra?= =?UTF-8?q?se=C3=B1a=20en=20interfaz=20de=20administrador?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Controllers/Configuracion/Users.php | 195 ++++++++++-------- ci4/app/Models/UserModel.php | 24 ++- .../themes/vuexy/form/user/_userFormItems.php | 70 ++++--- .../themes/vuexy/form/user/viewUserList.php | 13 +- 4 files changed, 169 insertions(+), 133 deletions(-) diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index a669d1d3..5bbfedba 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -1,4 +1,4 @@ -group_model = new GroupModel(); $this->group_user_model = new GroupsUsersModel(); @@ -46,31 +48,39 @@ class Users extends \App\Controllers\GoBaseController { ]; parent::initController($request, $response, $logger); - + } - public function index() { - + public function index() + { + $this->viewData['usingClientSideDataTable'] = true; - $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]); + $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]); $this->viewData['user_model'] = $this->user_model; - $this->viewData['userList2'] = $this->user_model->getUsersList(); + $this->viewData['userList2'] = auth()->getProvider()->findAll(); parent::index(); } - public function add() { + public function add() + { if ($this->request->getPost()) : $postData = $this->request->getPost(); - $currentGroups = $postData['group']??[]; + // Obtener contraseña nueva si se ha introducido en texto plano + if (empty($postData['password'])) { + $postData['password'] = 'Safekat2024'; // Contraseña por defecto + } + + $currentGroups = $postData['group'] ?? []; unset($postData['group']); + $postData['username'] = strstr($postData['email'], '@', true); - $sanitizedData = $this->sanitized($postData, true); + $sanitizedData = $this->sanitized($postData, true); $noException = true; @@ -78,40 +88,40 @@ class Users extends \App\Controllers\GoBaseController { if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : - try { + try { $user = new User([ 'username' => $sanitizedData['username'], 'first_name' => $sanitizedData['first_name'], 'last_name' => $sanitizedData['last_name'], - 'email' => $sanitizedData['email'], - 'password' => 'Safekat2024', - 'status' => $sanitizedData['status']??0, - 'active' => $sanitizedData['active']??0, + 'email' => $sanitizedData['email'], + 'password' => $sanitizedData['password'], + 'status' => $sanitizedData['status'] ?? 0, + 'active' => $sanitizedData['active'] ?? 0, ]); $users->save($user); $successfulResult = true; // Hacked - } catch (\Exception $e) { - $noException = false; - //$this->dealWithException($e); + } catch (\Exception $e) { + $noException = false; + //$this->dealWithException($e); if (strpos($e->getMessage(), 'correo duplicado') !== false) { $this->viewData['errorMessage'] = "El correo electrónico ya está registrado en el sistema"; $this->session->setFlashdata('formErrors', $this->model->errors()); } - - } - else: - $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); + + } + else: + $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); $this->session->setFlashdata('formErrors', $this->model->errors()); - endif; - - $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission + endif; + + $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission endif; if ($noException && $successfulResult) : $id = $users->getInsertID(); $this->group_user_model->where('user_id', $id)->delete(); - foreach($currentGroups as $group){ + foreach ($currentGroups as $group) { $group_user_data = [ 'user_id' => $id, 'group' => $group @@ -119,8 +129,7 @@ class Users extends \App\Controllers\GoBaseController { $this->group_user_model->insert($group_user_data); } - $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Users.user'))]) . 'Downloads'; - $message .= anchor(route_to('editUser', $id), lang('Basic.global.continueEditing').'?'); + $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Users.user'))]) . '.'; $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : @@ -141,88 +150,91 @@ class Users extends \App\Controllers\GoBaseController { $this->viewData['clienteList'] = $this->getClienteListItems(); $this->viewData['formAction'] = route_to('createUser'); $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); - $this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix'); - + $this->viewData['boxTitle'] = lang('Basic.global.addNew') . lang('Users.user') . ' ' . lang('Basic.global.addNewSuffix'); + return $this->displayForm(__METHOD__); } // end function add() - public function edit($requestedId = null) { - - if ($requestedId == null) : + public function edit($requestedId = null) + { + if ($requestedId == null) { return $this->redirect2listView(); - endif; + } $id = filter_var($requestedId, FILTER_SANITIZE_URL); - $user = $this->model->find($id); + $users = auth()->getProvider(); + $user = $users->findById($id); if ($user == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Users.user')), $id]); return $this->redirect2listView('errorMessage', $message); endif; - if ($this->request->getPost()) : $postData = $this->request->getPost(); - $currentGroups = $postData['group']; + $currentGroups = $postData['group'] ?? []; unset($postData['group']); + + // Obtener contraseña nueva si se ha introducido en texto plano + if (empty($postData['password'])) { + unset($postData['password']); + } + $sanitizedData = $this->sanitized($postData, true); - if ($this->request->getPost('status') == 0 ) { + if ($this->request->getPost('status') == 0) { $sanitizedData['status'] = null; } $noException = true; - if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + if ($successfulResult = $this->canValidate()) : + + if ($this->canValidate()) : + try { - if ($this->canValidate()) : - try { if (in_array('cliente-editor', $currentGroups) || in_array('cliente-administrador', $currentGroups)) { - if(!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) { + if (!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) { $this->viewData['errorMessage'] = lang('Users.errors.cliente_sin_clienteID'); $this->session->setFlashdata('formErrors', $this->model->errors()); - $successfulResult = false; + } else { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } - else{ - $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); - } - } - else { + } else { $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } - - } catch (\Exception $e) { - $noException = false; - $this->dealWithException($e); - } - else: - $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); - $this->session->setFlashdata('formErrors', $this->model->errors()); - - endif; + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); - $user->fill($sanitizedData); - $thenRedirect = false; + endif; + + $user->fill($sanitizedData); + $users->save($user); + $thenRedirect = false; endif; if ($noException && $successfulResult) : $this->group_user_model->where('user_id', $user->id)->delete(); - foreach($currentGroups as $group){ + foreach ($currentGroups as $group) { $group_user_data = [ 'user_id' => $user->id, 'group' => $group ]; $this->group_user_model->insert($group_user_data); } - + $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 = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Users.user'))]) . '.'; $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : @@ -234,7 +246,7 @@ class Users extends \App\Controllers\GoBaseController { else: $this->session->setFlashData('sweet-success', $message); endif; - + endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') @@ -243,13 +255,14 @@ class Users extends \App\Controllers\GoBaseController { $this->viewData['formAction'] = route_to('updateUser', $id); $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'); + $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) { + public function delete($requestedId = null, bool $deletePermanently = true) + { if ($requestedId == null) : return $this->redirect2listView(); @@ -264,26 +277,25 @@ class Users extends \App\Controllers\GoBaseController { endif; $users = auth()->getProvider(); - $users->delete($user->id, $deletePermanently); + $users->delete($user->id); $message = "Usuario eliminado correctamente"; return $this->redirect2listView('successMessage', $message); - } // end function delete(...) - - - public function allItemsSelect() { + + public function allItemsSelect() + { if ($this->request->isAJAX()) { $onlyActiveOnes = true; $reqVal = $this->request->getPost('val') ?? 'id_user'; - $menu = $this->model->getAllForMenu($reqVal.', first_name', 'first_name', $onlyActiveOnes, false); + $menu = $this->model->getAllForMenu($reqVal . ', first_name', 'first_name', $onlyActiveOnes, false); $nonItem = new \stdClass; $nonItem->id_user = ''; - $nonItem->first_name = '- '.lang('Basic.global.None').' -'; - array_unshift($menu , $nonItem); + $nonItem->first_name = '- ' . lang('Basic.global.None') . ' -'; + array_unshift($menu, $nonItem); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); @@ -296,8 +308,9 @@ class Users extends \App\Controllers\GoBaseController { return $this->failUnauthorized('Invalid request', 403); } } - - public function menuItems() { + + public function menuItems() + { if ($this->request->isAJAX()) { $searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0]; @@ -308,8 +321,8 @@ class Users extends \App\Controllers\GoBaseController { $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $nonItem = new \stdClass; $nonItem->id = ''; - $nonItem->text = '- '.lang('Basic.global.None').' -'; - array_unshift($menu , $nonItem); + $nonItem->text = '- ' . lang('Basic.global.None') . ' -'; + array_unshift($menu, $nonItem); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); @@ -323,10 +336,11 @@ class Users extends \App\Controllers\GoBaseController { } } - public function getMenuComerciales(){ + public function getMenuComerciales() + { if ($this->request->isAJAX()) { $comerciales = $this->model->getComerciales(); - + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ @@ -339,15 +353,16 @@ class Users extends \App\Controllers\GoBaseController { } } - - protected function getPaisListItems() { - $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])]; + + protected function getPaisListItems() + { + $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])]; $paisModel = model('App\Models\Configuracion\PaisModel'); $registers = $paisModel->findAll(); - return $registers; - } + return $registers; + } protected function getClienteListItems($selId = null) { @@ -362,5 +377,5 @@ class Users extends \App\Controllers\GoBaseController { endif; return $data; } - + } diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php index 934604ff..75788574 100644 --- a/ci4/app/Models/UserModel.php +++ b/ci4/app/Models/UserModel.php @@ -51,17 +51,23 @@ class UserModel extends ShieldUserModel } - public function getUsersList(){ + public function getUsersList() + { $builder = $this->db - ->table("users" . " t1") - ->select( - "t1.id AS id, t1.first_name AS first_name, t1.last_name AS last_name, t1.last_active AS last_active, t2.group AS group" - ); - - $builder->where('t1.deleted_at', null); - $builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left"); + ->table('users t1') + ->select(' + t1.id AS id, + t1.first_name AS first_name, + t1.last_name AS last_name, + t1.email AS email, + t1.last_active AS last_active, + GROUP_CONCAT(DISTINCT t2.`group` SEPARATOR ", ") AS `group` + ') + ->join('auth_groups_users t2', 't1.id = t2.user_id', 'left') + ->where('t1.deleted_at', null) + ->groupBy('t1.id, t1.first_name, t1.last_name, t1.email, t1.last_active'); return $builder->get()->getResult(); - } + } diff --git a/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php b/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php index ba0c3c02..f021565f 100644 --- a/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php @@ -1,26 +1,25 @@
-
-
+
- -
+
-
-
+ + +
+ + +
+
@@ -48,14 +64,14 @@ -
+
status); ?> - @@ -66,29 +82,29 @@ active); ?> - -
- - -
-
- -
+ +
+ + + +
+
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/user/viewUserList.php b/ci4/app/Views/themes/vuexy/form/user/viewUserList.php index 63935bc1..b22a4c76 100644 --- a/ci4/app/Views/themes/vuexy/form/user/viewUserList.php +++ b/ci4/app/Views/themes/vuexy/form/user/viewUserList.php @@ -17,8 +17,8 @@ - - + + @@ -46,11 +46,10 @@ last_name) || strlen($item->last_name) < 51 ? esc($item->last_name) : character_limiter(esc($item->last_name), 50) ?> - - group) ? "" : character_limiter(esc(lang('Users.' . $item->group)), 50) ?> - - - + + email) ? "" : character_limiter(esc(lang($item->email)), 50) ?> + + last_active) ? '' : date('d/m/Y H:m:s', strtotime($item->last_active)) ?> From ad26a70aede82850ed131339ab5809f8825fa4cd Mon Sep 17 00:00:00 2001 From: imnavajas Date: Mon, 15 Jul 2024 23:20:00 +0200 Subject: [PATCH 2/4] =?UTF-8?q?A=C3=B1adido=20cambio=20de=20contrase=C3=B1?= =?UTF-8?q?a=20en=20perfil=20de=20usuario=20(mejorar=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Controllers/Configuracion/Users.php | 195 ++++---- ci4/app/Controllers/Profile.php | 88 ++-- ci4/app/Language/es/App.php | 6 +- .../Views/themes/vuexy/form/profile/index.php | 50 +- .../themes/vuexy/form/profile/index_old.php | 444 ------------------ 5 files changed, 183 insertions(+), 600 deletions(-) delete mode 100644 ci4/app/Views/themes/vuexy/form/profile/index_old.php diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index a669d1d3..5bbfedba 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -1,4 +1,4 @@ -group_model = new GroupModel(); $this->group_user_model = new GroupsUsersModel(); @@ -46,31 +48,39 @@ class Users extends \App\Controllers\GoBaseController { ]; parent::initController($request, $response, $logger); - + } - public function index() { - + public function index() + { + $this->viewData['usingClientSideDataTable'] = true; - $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]); + $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]); $this->viewData['user_model'] = $this->user_model; - $this->viewData['userList2'] = $this->user_model->getUsersList(); + $this->viewData['userList2'] = auth()->getProvider()->findAll(); parent::index(); } - public function add() { + public function add() + { if ($this->request->getPost()) : $postData = $this->request->getPost(); - $currentGroups = $postData['group']??[]; + // Obtener contraseña nueva si se ha introducido en texto plano + if (empty($postData['password'])) { + $postData['password'] = 'Safekat2024'; // Contraseña por defecto + } + + $currentGroups = $postData['group'] ?? []; unset($postData['group']); + $postData['username'] = strstr($postData['email'], '@', true); - $sanitizedData = $this->sanitized($postData, true); + $sanitizedData = $this->sanitized($postData, true); $noException = true; @@ -78,40 +88,40 @@ class Users extends \App\Controllers\GoBaseController { if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : - try { + try { $user = new User([ 'username' => $sanitizedData['username'], 'first_name' => $sanitizedData['first_name'], 'last_name' => $sanitizedData['last_name'], - 'email' => $sanitizedData['email'], - 'password' => 'Safekat2024', - 'status' => $sanitizedData['status']??0, - 'active' => $sanitizedData['active']??0, + 'email' => $sanitizedData['email'], + 'password' => $sanitizedData['password'], + 'status' => $sanitizedData['status'] ?? 0, + 'active' => $sanitizedData['active'] ?? 0, ]); $users->save($user); $successfulResult = true; // Hacked - } catch (\Exception $e) { - $noException = false; - //$this->dealWithException($e); + } catch (\Exception $e) { + $noException = false; + //$this->dealWithException($e); if (strpos($e->getMessage(), 'correo duplicado') !== false) { $this->viewData['errorMessage'] = "El correo electrónico ya está registrado en el sistema"; $this->session->setFlashdata('formErrors', $this->model->errors()); } - - } - else: - $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); + + } + else: + $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); $this->session->setFlashdata('formErrors', $this->model->errors()); - endif; - - $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission + endif; + + $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission endif; if ($noException && $successfulResult) : $id = $users->getInsertID(); $this->group_user_model->where('user_id', $id)->delete(); - foreach($currentGroups as $group){ + foreach ($currentGroups as $group) { $group_user_data = [ 'user_id' => $id, 'group' => $group @@ -119,8 +129,7 @@ class Users extends \App\Controllers\GoBaseController { $this->group_user_model->insert($group_user_data); } - $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Users.user'))]) . 'Downloads'; - $message .= anchor(route_to('editUser', $id), lang('Basic.global.continueEditing').'?'); + $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Users.user'))]) . '.'; $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : @@ -141,88 +150,91 @@ class Users extends \App\Controllers\GoBaseController { $this->viewData['clienteList'] = $this->getClienteListItems(); $this->viewData['formAction'] = route_to('createUser'); $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); - $this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix'); - + $this->viewData['boxTitle'] = lang('Basic.global.addNew') . lang('Users.user') . ' ' . lang('Basic.global.addNewSuffix'); + return $this->displayForm(__METHOD__); } // end function add() - public function edit($requestedId = null) { - - if ($requestedId == null) : + public function edit($requestedId = null) + { + if ($requestedId == null) { return $this->redirect2listView(); - endif; + } $id = filter_var($requestedId, FILTER_SANITIZE_URL); - $user = $this->model->find($id); + $users = auth()->getProvider(); + $user = $users->findById($id); if ($user == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Users.user')), $id]); return $this->redirect2listView('errorMessage', $message); endif; - if ($this->request->getPost()) : $postData = $this->request->getPost(); - $currentGroups = $postData['group']; + $currentGroups = $postData['group'] ?? []; unset($postData['group']); + + // Obtener contraseña nueva si se ha introducido en texto plano + if (empty($postData['password'])) { + unset($postData['password']); + } + $sanitizedData = $this->sanitized($postData, true); - if ($this->request->getPost('status') == 0 ) { + if ($this->request->getPost('status') == 0) { $sanitizedData['status'] = null; } $noException = true; - if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + if ($successfulResult = $this->canValidate()) : + + if ($this->canValidate()) : + try { - if ($this->canValidate()) : - try { if (in_array('cliente-editor', $currentGroups) || in_array('cliente-administrador', $currentGroups)) { - if(!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) { + if (!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) { $this->viewData['errorMessage'] = lang('Users.errors.cliente_sin_clienteID'); $this->session->setFlashdata('formErrors', $this->model->errors()); - $successfulResult = false; + } else { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } - else{ - $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); - } - } - else { + } else { $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } - - } catch (\Exception $e) { - $noException = false; - $this->dealWithException($e); - } - else: - $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); - $this->session->setFlashdata('formErrors', $this->model->errors()); - - endif; + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); - $user->fill($sanitizedData); - $thenRedirect = false; + endif; + + $user->fill($sanitizedData); + $users->save($user); + $thenRedirect = false; endif; if ($noException && $successfulResult) : $this->group_user_model->where('user_id', $user->id)->delete(); - foreach($currentGroups as $group){ + foreach ($currentGroups as $group) { $group_user_data = [ 'user_id' => $user->id, 'group' => $group ]; $this->group_user_model->insert($group_user_data); } - + $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 = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Users.user'))]) . '.'; $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : @@ -234,7 +246,7 @@ class Users extends \App\Controllers\GoBaseController { else: $this->session->setFlashData('sweet-success', $message); endif; - + endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') @@ -243,13 +255,14 @@ class Users extends \App\Controllers\GoBaseController { $this->viewData['formAction'] = route_to('updateUser', $id); $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'); + $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) { + public function delete($requestedId = null, bool $deletePermanently = true) + { if ($requestedId == null) : return $this->redirect2listView(); @@ -264,26 +277,25 @@ class Users extends \App\Controllers\GoBaseController { endif; $users = auth()->getProvider(); - $users->delete($user->id, $deletePermanently); + $users->delete($user->id); $message = "Usuario eliminado correctamente"; return $this->redirect2listView('successMessage', $message); - } // end function delete(...) - - - public function allItemsSelect() { + + public function allItemsSelect() + { if ($this->request->isAJAX()) { $onlyActiveOnes = true; $reqVal = $this->request->getPost('val') ?? 'id_user'; - $menu = $this->model->getAllForMenu($reqVal.', first_name', 'first_name', $onlyActiveOnes, false); + $menu = $this->model->getAllForMenu($reqVal . ', first_name', 'first_name', $onlyActiveOnes, false); $nonItem = new \stdClass; $nonItem->id_user = ''; - $nonItem->first_name = '- '.lang('Basic.global.None').' -'; - array_unshift($menu , $nonItem); + $nonItem->first_name = '- ' . lang('Basic.global.None') . ' -'; + array_unshift($menu, $nonItem); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); @@ -296,8 +308,9 @@ class Users extends \App\Controllers\GoBaseController { return $this->failUnauthorized('Invalid request', 403); } } - - public function menuItems() { + + public function menuItems() + { if ($this->request->isAJAX()) { $searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0]; @@ -308,8 +321,8 @@ class Users extends \App\Controllers\GoBaseController { $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $nonItem = new \stdClass; $nonItem->id = ''; - $nonItem->text = '- '.lang('Basic.global.None').' -'; - array_unshift($menu , $nonItem); + $nonItem->text = '- ' . lang('Basic.global.None') . ' -'; + array_unshift($menu, $nonItem); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); @@ -323,10 +336,11 @@ class Users extends \App\Controllers\GoBaseController { } } - public function getMenuComerciales(){ + public function getMenuComerciales() + { if ($this->request->isAJAX()) { $comerciales = $this->model->getComerciales(); - + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ @@ -339,15 +353,16 @@ class Users extends \App\Controllers\GoBaseController { } } - - protected function getPaisListItems() { - $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])]; + + protected function getPaisListItems() + { + $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])]; $paisModel = model('App\Models\Configuracion\PaisModel'); $registers = $paisModel->findAll(); - return $registers; - } + return $registers; + } protected function getClienteListItems($selId = null) { @@ -362,5 +377,5 @@ class Users extends \App\Controllers\GoBaseController { endif; return $data; } - + } diff --git a/ci4/app/Controllers/Profile.php b/ci4/app/Controllers/Profile.php index d18708e8..71772a74 100755 --- a/ci4/app/Controllers/Profile.php +++ b/ci4/app/Controllers/Profile.php @@ -7,52 +7,25 @@ use App\Models\UserModel; class Profile extends BaseController { - private $user_model; - private $id_user; - function __construct() { - $this->user_model = new UserModel(); - $this->id_user = auth()->user()->id; } public function index() { - helper('file'); - helper('form'); - helper('text'); - - $data['title'] = [ - 'module' => lang("App.profile_title"), - 'page' => lang("App.profile_subtitle"), - 'icon' => 'fas fa-user' - ]; $data['breadcrumb'] = [ ['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false], ['title' => lang("App.profile_title"), 'route' => "", 'active' => true] ]; - $data['btn_return'] = [ - 'title' => lang("App.global_come_back"), - 'route' => '/', - 'class' => 'btn btn-dark mr-1', - 'icon' => 'fas fa-angle-left' - ]; - - $data['btn_submit'] = [ - 'title' => lang("App.global_save"), - 'route' => '', - 'class' => 'btn btn-primary mr-1', - 'icon' => 'fas fa-save' - ]; - - $session = session(); - - $data['obj'] = $this->user_model->where('id', $this->id_user)->first(); + // Get the User Provider (UserModel by default) + $users = auth()->getProvider(); + // Find by the user_id + $data['obj'] = $users->findById(auth()->id()); echo view(getenv('theme.path') . 'form/profile/index', $data); @@ -60,38 +33,55 @@ class Profile extends BaseController public function store() { - $session = session(); helper('form'); $rules = [ 'first_name' => 'required', 'last_name' => 'required', + 'new_pwd' => 'permit_empty|min_length[8]', + 'new_pwd_confirm' => 'required_with[new_pwd]|matches[new_pwd]' ]; + // Definir los mensajes de error personalizados $rules_error = [ 'first_name' => ['required' => lang("App.profile_rules_first_name_r")], 'last_name' => ['required' => lang("App.profile_rules_last_name_r")], + 'new_pwd' => ['min_length' => lang("App.profile_rules_password_m")], + 'new_pwd_confirm' => [ + 'matches' => lang("App.profile_rules_password_confirm_m") + ] ]; - - if ($this->validate($rules ?? [], $rules_error ?? [])) { - if (!empty($this->id_user)) { - $this->user_model->save([ - 'id' => $this->id_user, - 'first_name' => $this->request->getPost('first_name'), - 'last_name' => $this->request->getPost('last_name') - ]); - $session->setFlashdata('sweet', ['success', lang("App.global_alert_save_success")]); - } else { - $session->setFlashdata('sweet', ['error', lang("App.global_alert_save_error")]); - } - } else { - - $session->setFlashdata('error', 'error'); - return $this->index(); + // Validar la entrada + if (!$this->validate($rules, $rules_error)) { + // Si la validación falla, redirigir de vuelta con errores + return redirect()->back()->withInput()->with('errors', $this->validator->getErrors()); } - return redirect()->to('/profile'); + // Obtener los valores de los campos + $firstName = $this->request->getPost('first_name'); + $lastName = $this->request->getPost('last_name'); + $newPwd = $this->request->getPost('new_pwd'); + + $update_data = [ + 'first_name' => $firstName, + 'last_name' => $lastName, + 'password' => $newPwd, + ]; + + if(empty($newPwd)){ + unset($update_data['password']); + } + + // Aquí debes obtener el usuario actual, por ejemplo, desde la sesión + $users = auth()->getProvider(); + $user = $users->findById(auth()->id()); + $user->fill($update_data); + $users->save($user); + + // Redirigir con un mensaje de éxito + return redirect()->back()->with('success', lang('App.profile_updated_successfully')); + } } diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 5e607b58..e03fa10d 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -137,9 +137,9 @@ return [ "profile_mobile" => "Teléfono Móvil", "profile_mobile_ph" => "Escriba su número de celular", "profile_password" => "Cambiar Contraseña", - "profile_password_ph" => "Escribe tu contraseña", - "profile_confirm_password" => "Confirmar seña", - "profile_confirm_password_ph" => "Confirma tu contraseña anterior", + "profile_password_ph" => "Escribe nueva contraseña para cambiarla", + "profile_confirm_password" => "Confirmar contraseña", + "profile_confirm_password_ph" => "Confirma tu contraseña anterior para cambiarla", "profile_date_birth" => "Fecha de Nacimiento", "profile_date_birth_ph" => "Seleccionar fecha de nacimiento", "profile_address" => "Dirección", diff --git a/ci4/app/Views/themes/vuexy/form/profile/index.php b/ci4/app/Views/themes/vuexy/form/profile/index.php index 58eee725..bff0c49f 100644 --- a/ci4/app/Views/themes/vuexy/form/profile/index.php +++ b/ci4/app/Views/themes/vuexy/form/profile/index.php @@ -1,4 +1,3 @@ -include("themes/_commonPartialsBs/select2bs5") ?> extend('themes/vuexy/main/general_settings_layout') ?> section('content'); ?> @@ -12,10 +11,11 @@
">
-
- +
+
-
- +
+
-
+
" value="email : set_value('email'); ?>" />
+
+ + " + value="" + /> +
+
+ + " + value="" + /> +
- - + + "btn btn-danger"]) ?>
@@ -96,12 +123,7 @@ section('additionalInlineJs') ?> "use strict"; $(document).ready(function () { -$('#first_name').focus(); + $('#first_name').focus(); }); -$('.file-upload').on('click', function (e) { -e.preventDefault(); -$('#file').trigger('click'); -}); - endSection() ?> diff --git a/ci4/app/Views/themes/vuexy/form/profile/index_old.php b/ci4/app/Views/themes/vuexy/form/profile/index_old.php deleted file mode 100644 index c0aadbd7..00000000 --- a/ci4/app/Views/themes/vuexy/form/profile/index_old.php +++ /dev/null @@ -1,444 +0,0 @@ - -" - rel="stylesheet"> - - -
-
-
-
-
-

- -
-
-
- -
-
-
-
-
-
-

-
-
- -
" method="post"> - -
-
-
- -
-
-
- - " - value="first_name : set_value('first_name'); ?>"> -
-
-
-
- - " - value="last_name : set_value('last_name'); ?>"> -
-
-
-
- - " - id="date_birth" name="date_birth" - value="date_birth : set_value('date_birth'); ?>"> -
-
-
-
- - " - value="email : set_value('email'); ?>" - disabled> -
-
-
-
- - " - value="mobile : set_value('mobile'); ?>"> -
-
-
-
- - "> -
-
-
-
- - "> -
-
-
-
-
- -
-
-
- - " - value="address : set_value('address'); ?>"> -
-
-
-
- - " - value="city : set_value('city'); ?>"> -
-
-
-
- - " - value="state : set_value('state'); ?>"> -
-
-
-
- - country ?? [] : set_value('country'); ?> - -
-
-
-
- - language ?? [] : set_value('language'); ?> - -
-
-
-
-
- - - - -
-
-
-
-
-
-
-
-

-
-
-
-
- -
-
- first_name ?? '' ?>
- email ?? '' ?> -
-
- -
- - -
-
-
-
-
- get('settings'); ?> - - -
" method="post" id="sendFormTFA"> - -
-
-
-
-
-
-

-
-
-
- > - -
-
-
-
-
-
- GetQR("{$settings['title']} ({$name})", $tfa_secret); - } else { - $tfa_secret = $tfa->createSecret(); - $qrcode = $tfa->GetQR("{$settings['title']} ({$name})", $tfa_secret); - } - ?> -
-
-

- -
-
-

- ' . $item . ''; - } - } else { - $codes = array(); - for ($i = 1; $i <= 8; $i++) { - $code = random_string('numeric', 6); - $codes[] = $code; - echo '' . $code . ''; - } - } - ?> -


- - - -
-
-
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - - From 944f92f3b0305e6662e6d89b342e6a14ba81814c Mon Sep 17 00:00:00 2001 From: imnavajas Date: Tue, 16 Jul 2024 09:26:03 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Terminada=20gestion=20de=20contrase=C3=B1as?= =?UTF-8?q?=20de=20usuarios=20en=20perfil=20y=20zona=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Config/Auth.php | 1 + ci4/app/Controllers/Configuracion/Users.php | 2 +- ci4/app/Controllers/Profile.php | 2 +- ci4/app/Entities/Usuarios/UserEntity.php | 21 +- ci4/app/Entities/Usuarios/UsersEntity.php | 14 +- ci4/app/Models/UserModel.php | 3 + .../profile/{index.php => profileDetails.php} | 32 +- .../themes/vuexy/main/activities_layout.php | 357 ----------- ci4/app/Views/themes/vuexy/main/all.php | 570 ------------------ .../Views/themes/vuexy/main/defaultlayout.php | 12 +- ci4/app/Views/themes/vuexy/main/demo_view.php | 297 --------- .../vuexy/main/general_settings_layout.php | 359 ----------- .../themes/vuexy/main/presupuestos_layout.php | 4 +- sk-new-branch.bat | 20 - 14 files changed, 39 insertions(+), 1655 deletions(-) rename ci4/app/Views/themes/vuexy/form/profile/{index.php => profileDetails.php} (76%) delete mode 100644 ci4/app/Views/themes/vuexy/main/activities_layout.php delete mode 100644 ci4/app/Views/themes/vuexy/main/all.php delete mode 100644 ci4/app/Views/themes/vuexy/main/demo_view.php delete mode 100644 ci4/app/Views/themes/vuexy/main/general_settings_layout.php delete mode 100755 sk-new-branch.bat diff --git a/ci4/app/Config/Auth.php b/ci4/app/Config/Auth.php index c917571c..57efc4ca 100644 --- a/ci4/app/Config/Auth.php +++ b/ci4/app/Config/Auth.php @@ -13,6 +13,7 @@ declare(strict_types=1); namespace Config; +use App\Entities\Usuarios\UsersEntity; use App\Models\UserModel; use CodeIgniter\Shield\Authentication\Passwords\ValidationRules; use CodeIgniter\Shield\Config\Auth as ShieldAuth; diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index 5bbfedba..c78ca50d 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -150,7 +150,7 @@ class Users extends \App\Controllers\GoBaseController $this->viewData['clienteList'] = $this->getClienteListItems(); $this->viewData['formAction'] = route_to('createUser'); $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); - $this->viewData['boxTitle'] = lang('Basic.global.addNew') . lang('Users.user') . ' ' . lang('Basic.global.addNewSuffix'); + $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Users.user') . ' ' . lang('Basic.global.addNewSuffix'); return $this->displayForm(__METHOD__); diff --git a/ci4/app/Controllers/Profile.php b/ci4/app/Controllers/Profile.php index 71772a74..67449c84 100755 --- a/ci4/app/Controllers/Profile.php +++ b/ci4/app/Controllers/Profile.php @@ -27,7 +27,7 @@ class Profile extends BaseController // Find by the user_id $data['obj'] = $users->findById(auth()->id()); - echo view(getenv('theme.path') . 'form/profile/index', $data); + echo view(getenv('theme.path') . 'form/profile/profileDetails', $data); } diff --git a/ci4/app/Entities/Usuarios/UserEntity.php b/ci4/app/Entities/Usuarios/UserEntity.php index 0c1d5383..61f750ce 100755 --- a/ci4/app/Entities/Usuarios/UserEntity.php +++ b/ci4/app/Entities/Usuarios/UserEntity.php @@ -24,18 +24,25 @@ class UserEntity extends \CodeIgniter\Entity\Entity "cliente_id" => "int", "active" => "boolean", ]; + /** - * Returns a full name: "first last" + * Get the full name of the user * - * @return string + * If the first name and last name are available, the full name is generated as "{first name} {last name}". + * If the first name or last name is missing, only the available name is used. + * If both the first name and last name are missing, the username is used as the full name. + * + * @return string The full name of the user */ public function getFullName() { - $fullName = - (!empty($this->attributes["first_name"]) ? trim($this->attributes["first_name"]) . " " : "") . - (!empty($this->attributes["last_name"]) ? trim($this->attributes["last_name"]) : ""); - $name = empty($fullName) ? $this->attributes["username"] : $fullName; - return $name; + $firstName = trim($this->attributes["first_name"] ?? ""); + $lastName = trim($this->attributes["last_name"] ?? ""); + $fullName = $firstName . ' ' . $lastName; + $fullName = trim($fullName); // In case first name is empty, this will remove the leading space + + // Use the username attribute if the full name is still empty after trimming + return $fullName ?: $this->attributes["username"]; } /** diff --git a/ci4/app/Entities/Usuarios/UsersEntity.php b/ci4/app/Entities/Usuarios/UsersEntity.php index 7ff93bb7..84ae01f1 100644 --- a/ci4/app/Entities/Usuarios/UsersEntity.php +++ b/ci4/app/Entities/Usuarios/UsersEntity.php @@ -1,7 +1,6 @@ attributes["first_name"] ?? ""); + $lastName = trim($this->attributes["last_name"] ?? ""); + $fullName = $firstName . ' ' . $lastName; + $fullName = trim($fullName); // In case first name is empty, this will remove the leading space + + // Use the username attribute if the full name is still empty after trimming + return $fullName ?: $this->attributes["username"]; + } + + } diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php index 75788574..63d8acfa 100644 --- a/ci4/app/Models/UserModel.php +++ b/ci4/app/Models/UserModel.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Models; +use App\Entities\Usuarios\UsersEntity; use CodeIgniter\Shield\Models\UserModel as ShieldUserModel; class UserModel extends ShieldUserModel @@ -20,6 +21,8 @@ class UserModel extends ShieldUserModel ]; } + protected $returnType = UsersEntity::class; + protected $useSoftDeletes = true; protected $useTimestamps = true; protected $createdField = 'created_at'; diff --git a/ci4/app/Views/themes/vuexy/form/profile/index.php b/ci4/app/Views/themes/vuexy/form/profile/profileDetails.php similarity index 76% rename from ci4/app/Views/themes/vuexy/form/profile/index.php rename to ci4/app/Views/themes/vuexy/form/profile/profileDetails.php index bff0c49f..4a9fc610 100644 --- a/ci4/app/Views/themes/vuexy/form/profile/index.php +++ b/ci4/app/Views/themes/vuexy/form/profile/profileDetails.php @@ -1,4 +1,4 @@ -extend('themes/vuexy/main/general_settings_layout') ?> +extend('themes/vuexy/main/defaultlayout') ?> section('content'); ?> @@ -75,40 +75,12 @@
- "btn btn-danger"]) ?> + "btn btn-dark"]) ?>
- - - - get('settings'); ?> diff --git a/ci4/app/Views/themes/vuexy/main/activities_layout.php b/ci4/app/Views/themes/vuexy/main/activities_layout.php deleted file mode 100644 index a5534604..00000000 --- a/ci4/app/Views/themes/vuexy/main/activities_layout.php +++ /dev/null @@ -1,357 +0,0 @@ -get('token') ?? ''; -$tfa = $session->get('tfa') ?? false; -$settings = $session->get('settings'); - -$picture = "/assets/img/default-user.png"; -$pulse = session()->get('pulse'); -$notification = session()->get('notification'); - -if (!empty($token) && $tfa == false) { - //echo ""; -} -?> - - - - - - - - - - <?= config('Safekat')->appName ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - renderSection('css') ?> - - - - - - - - - - - -
-
- - - - -
- - - - - - -
- - -
-
- -
- - renderSection('content') ?> - -
- - - - - - -
-
- -
- -
- - -
- - -
-
- - -renderSection('footerAdditions') ?> - - - - - - - - - - - - -renderSection('additionalExternalJs') ?> - - - - - - - - - - - - - - diff --git a/ci4/app/Views/themes/vuexy/main/all.php b/ci4/app/Views/themes/vuexy/main/all.php deleted file mode 100644 index fd8f2ef2..00000000 --- a/ci4/app/Views/themes/vuexy/main/all.php +++ /dev/null @@ -1,570 +0,0 @@ -get('settings'); -$picture = "/assets/img/default-user.png"; -?> - - - - - - - - - <?= config('Safekat')->appName ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - -
- - - - - - -
- -
-
- -
-

- Sample page. -

-
- - - - - - -
-
- -
- -
- - -
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ci4/app/Views/themes/vuexy/main/defaultlayout.php b/ci4/app/Views/themes/vuexy/main/defaultlayout.php index 5f8ecdd7..4d03e697 100644 --- a/ci4/app/Views/themes/vuexy/main/defaultlayout.php +++ b/ci4/app/Views/themes/vuexy/main/defaultlayout.php @@ -133,7 +133,6 @@ $picture = "/assets/img/default-user.png"; title="Acceso directo a buscador de presupuestos" > - @@ -232,8 +231,8 @@ $picture = "/assets/img/default-user.png";
- get('first_name') . ' ' . $session->get('last_name') ?> - Admin + user()->getFullName(); ?> + user()->getEmail(); ?>
@@ -247,13 +246,6 @@ $picture = "/assets/img/default-user.png"; - - - - - - -
  • diff --git a/ci4/app/Views/themes/vuexy/main/demo_view.php b/ci4/app/Views/themes/vuexy/main/demo_view.php deleted file mode 100644 index e69defe8..00000000 --- a/ci4/app/Views/themes/vuexy/main/demo_view.php +++ /dev/null @@ -1,297 +0,0 @@ -get('token') ?? ''; -$tfa = $session->get('tfa') ?? false; -$settings = $session->get('settings'); - -$picture = "/assets/img/default-user.png"; -$pulse = session()->get('pulse'); -$notification = session()->get('notification'); - -if (!empty($token) && $tfa == false) { - //echo ""; -} -?> - - - - - - - - - <?= config('Safekat')->appName ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - - -
    - - - - - - -
    - - -
    -

    - Safekat / - -

    -
    - -
    -
    -
    Prueba privilegios
    -
    -
    - - - -
    -
    - -
    -
    -
    - -
    - - - - - - -
    -
    - -
    - -
    - - -
    - - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ci4/app/Views/themes/vuexy/main/general_settings_layout.php b/ci4/app/Views/themes/vuexy/main/general_settings_layout.php deleted file mode 100644 index b1b9aa2b..00000000 --- a/ci4/app/Views/themes/vuexy/main/general_settings_layout.php +++ /dev/null @@ -1,359 +0,0 @@ -get('token') ?? ''; -$tfa = $session->get('tfa') ?? false; -$settings = $session->get('settings'); - -$picture = "/assets/img/default-user.png"; -$pulse = session()->get('pulse'); -$notification = session()->get('notification'); - -if (!empty($token) && $tfa == false) { - //echo ""; -} -?> - - - - - - - - - - <?= config('Safekat')->appName ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - renderSection('css') ?> - - - - - - - - - - - -
    -
    - - - - -
    - - - - - - -
    - - -
    -
    - -
    - - renderSection('content') ?> - -
    - - - - - - -
    -
    - -
    - -
    - - -
    - - -
    -
    - - -renderSection('footerAdditions') ?> - - - - - - - - - - - - -renderSection('additionalExternalJs') ?> - - - - - - - - - - - - - diff --git a/ci4/app/Views/themes/vuexy/main/presupuestos_layout.php b/ci4/app/Views/themes/vuexy/main/presupuestos_layout.php index 91c4fd3b..aa7d3c7a 100644 --- a/ci4/app/Views/themes/vuexy/main/presupuestos_layout.php +++ b/ci4/app/Views/themes/vuexy/main/presupuestos_layout.php @@ -247,8 +247,8 @@ if (!empty($token) && $tfa == false) {
    - get('first_name') . ' ' . $session->get('last_name') ?> - Admin + user()->getFullName(); ?> + user()->getEmail(); ?>
    diff --git a/sk-new-branch.bat b/sk-new-branch.bat deleted file mode 100755 index 4ce0d215..00000000 --- a/sk-new-branch.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -REM Solicitar al usuario el nombre de la nueva rama -set /p nombre_rama=Nuevo nombre de la rama: - -echo %nombre_rama% - -REM Verificar si se proporciona un nombre de rama -if not "%nombre_rama%"=="" ( - REM Cambiar y actualizar la rama main - git checkout main - git pull - REM Crear nueva rama - git checkout -b %nombre_rama% - REM Hacer push de la nueva rama al repositorio remoto - git push -u origin %nombre_rama% - echo Se ha creado (a partir de la rama main) y cambiado a la nueva rama: %nombre_rama% -) else ( - echo No se proporcionó un nombre de rama. La creación de la rama ha sido omitida. -) From 0b6ce06c965f92b86eb5e68778c841e6b2cd85e4 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Tue, 16 Jul 2024 22:52:05 +0200 Subject: [PATCH 4/4] =?UTF-8?q?A=C3=B1adido=20campo=20de=20verficacion=20d?= =?UTF-8?q?e=20contrase=C3=B1a=20y=20campo=20de=20notas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Controllers/Configuracion/Users.php | 19 +- ci4/app/Entities/Usuarios/UsersEntity.php | 8 +- ci4/app/Language/es/Users.php | 12 -- ci4/app/Models/UserModel.php | 57 +++--- .../themes/vuexy/form/user/_userFormItems.php | 162 +++++++++++------- 5 files changed, 150 insertions(+), 108 deletions(-) diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index c78ca50d..a48c1b28 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -53,15 +53,12 @@ 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; - $this->viewData['userList2'] = auth()->getProvider()->findAll(); parent::index(); - } public function add() @@ -72,21 +69,24 @@ class Users extends \App\Controllers\GoBaseController $postData = $this->request->getPost(); // Obtener contraseña nueva si se ha introducido en texto plano - if (empty($postData['password'])) { + if (empty($postData['new_pwd'])) { $postData['password'] = 'Safekat2024'; // Contraseña por defecto + }else{ + $postData['password'] = $postData['new_pwd']; } - + // Obtener los grupos a los que pertenece $currentGroups = $postData['group'] ?? []; unset($postData['group']); - + // Generar el nombre de usuario $postData['username'] = strstr($postData['email'], '@', true); $sanitizedData = $this->sanitized($postData, true); $noException = true; + // Obtener proveedor de usuarios $users = auth()->getProvider(); - if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + if ($successfulResult = $this->canValidate()) : if ($this->canValidate()) : try { @@ -179,8 +179,9 @@ class Users extends \App\Controllers\GoBaseController unset($postData['group']); // Obtener contraseña nueva si se ha introducido en texto plano - if (empty($postData['password'])) { - unset($postData['password']); + // Obtener contraseña nueva si se ha introducido en texto plano + if (!empty($postData['new_pwd'])) { + $postData['password'] = $postData['new_pwd']; } $sanitizedData = $this->sanitized($postData, true); diff --git a/ci4/app/Entities/Usuarios/UsersEntity.php b/ci4/app/Entities/Usuarios/UsersEntity.php index 84ae01f1..51da0555 100644 --- a/ci4/app/Entities/Usuarios/UsersEntity.php +++ b/ci4/app/Entities/Usuarios/UsersEntity.php @@ -6,11 +6,13 @@ use CodeIgniter\Shield\Entities\User; class UsersEntity extends User { protected $attributes = [ - "first_name" => null, - "last_name" => null + 'first_name' => null, + 'last_name'=> null, + 'cliente_id' => null, + 'comments' => null, ]; protected $casts = [ - + "cliente_id" => "int", ]; public function getFullName() diff --git a/ci4/app/Language/es/Users.php b/ci4/app/Language/es/Users.php index 3417f937..98e0c86f 100755 --- a/ci4/app/Language/es/Users.php +++ b/ci4/app/Language/es/Users.php @@ -153,18 +153,6 @@ return [ ], - 'tfa_code' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - 'required' => 'El campo {field} es obligatorio.', - - ], - - 'tfa_secret' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - 'required' => 'El campo {field} es obligatorio.', - - ], - 'email' => [ 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', 'required' => 'El campo {field} es obligatorio.', diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php index 63d8acfa..ccc79a9c 100644 --- a/ci4/app/Models/UserModel.php +++ b/ci4/app/Models/UserModel.php @@ -18,6 +18,7 @@ class UserModel extends ShieldUserModel 'first_name', // Añadido 'last_name', // Añadido 'cliente_id', // Añadido + 'comments', // Añadido ]; } @@ -27,19 +28,41 @@ class UserModel extends ShieldUserModel protected $useTimestamps = true; protected $createdField = 'created_at'; protected $updatedField = 'updated_at'; - protected $deletedField = 'deleted_at'; + protected $deletedField = 'deleted_at'; + - protected $validationRules = [ - "username" => [ - "label" => "correo duplicado", - "rules" => "is_unique[users.username]", - ] + "first_name" => "required|trim|max_length[150]", + "last_name" => "required|trim|max_length[150]", + 'new_pwd' => 'permit_empty|min_length[8]', + 'new_pwd_confirm' => 'permit_empty|required_with[new_pwd]|matches[new_pwd]', + "comments" => "permit_empty|trim|max_length[512]" + ]; + + protected $validationMessages = [ + 'first_name' => [ + "max_length" => "Users.validation.first_name.max_length", + "required" => "Users.validation.first_name.required" + ], + 'last_name' => [ + "max_length" => "Users.validation.last_name.max_length", + "required" => "Users.validation.last_name.required" + ], + 'new_pwd' => [ + 'min_length' => "App.profile_rules_password_m" + ], + 'new_pwd_confirm' => [ + 'matches' => "App.profile_rules_password_confirm_m" + ], + 'comments' => [ + "max_length" => "Users.validation.last_name.max_length", + ], ]; - public function getComerciales(){ - + public function getComerciales() + { + $builder = $this->db ->table("users" . " t1") ->select( @@ -54,23 +77,5 @@ class UserModel extends ShieldUserModel } - public function getUsersList() - { - $builder = $this->db - ->table('users t1') - ->select(' - t1.id AS id, - t1.first_name AS first_name, - t1.last_name AS last_name, - t1.email AS email, - t1.last_active AS last_active, - GROUP_CONCAT(DISTINCT t2.`group` SEPARATOR ", ") AS `group` - ') - ->join('auth_groups_users t2', 't1.id = t2.user_id', 'left') - ->where('t1.deleted_at', null) - ->groupBy('t1.id, t1.first_name, t1.last_name, t1.email, t1.last_active'); - - return $builder->get()->getResult(); - } } diff --git a/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php b/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php index f021565f..d394dc4e 100644 --- a/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php @@ -1,21 +1,37 @@ -
    -
    -
    - - +
    +
    +
    +
    + + +
    -
    - - +
    +
    + + +
    +
    +
    + + +
    +
    +
    + +
    @@ -36,7 +52,6 @@
    -
    +
    - -
    - -
    - -
    - - +
    +
    +
    + + status); ?> + +
    -
    - - status); ?> - +
    +
    + + active); ?> + +
    +
    +
    + +
    +
    +
    + + +
    -
    - - active); ?> - +
    +
    + + +
    +
    +
    -
    +
    + +
    + -
    -
    \ No newline at end of file