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 @@ -