Añadido campo de verficacion de contraseña y campo de notas

This commit is contained in:
imnavajas
2024-07-16 22:52:05 +02:00
parent 57688a5310
commit 0b6ce06c96
5 changed files with 150 additions and 108 deletions

View File

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

View File

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

View File

@ -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.',

View File

@ -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();
}
}

View File

@ -1,21 +1,37 @@
<div class="row">
<div class="col-md-12 col-lg-6 px-4">
<div class="mb-3">
<label for="firstName" class="form-label">
<?= lang('Users.firstName') ?>
</label>
<input tabindex="1" type="text" id="firstName" name="first_name" maxLength="150" class="form-control"
value="<?= old('first_name', $user->first_name) ?>">
<div class="col-md-12 col-lg-12 px-4">
<div class="row">
<div class="col-md-6 col-lg-4">
<div class="mb-3">
<label for="firstName" class="form-label">
<?= lang('Users.firstName') ?> *
</label>
<input tabindex="1" type="text" id="firstName" name="first_name" maxLength="150" class="form-control"
value="<?= old('first_name', $user->first_name) ?>">
</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">
<?= lang('Users.email') ?>*
</label>
<input tabindex="3" type="email" id="email" name="email" maxLength="150" class="form-control"
value="<?= old('email', $user->email) ?>">
<div class="col-md-6 col-lg-4">
<div class="mb-3">
<label for="lastName" class="form-label">
<?= lang('Users.lastName') ?> *
</label>
<input tabindex="2" type="text" id="lastName" name="last_name" maxLength="150" class="form-control"
value="<?= old('last_name', $user->last_name) ?>">
</div>
</div>
<div class="col-md-6 col-lg-4">
<div class="mb-3">
<label for="email" class="form-label">
<?= lang('Users.email') ?>*
</label>
<input tabindex="3" type="email" id="email" name="email" maxLength="150" class="form-control"
value="<?= old('email', $user->email) ?>">
</div>
</div>
</div>
<div class="row">
<div class="mb-3">
<div class="form-group">
<label for="group" class="form-label"> <?= lang('Users.group') ?></label>
@ -36,7 +52,6 @@
</select>
</div>
</div>
<div class="mb-3">
<label for="cliente_id" class="form-label">
<?= lang('Presupuestos.clienteId') ?>
@ -52,59 +67,90 @@
endif; ?>
</select>
</div>
</div>
</div><!--//.col -->
<div class="col-md-12 col-lg-6 px-4">
<div class="mb-3">
<label for="lastName" class="form-label">
<?= lang('Users.lastName') ?>
</label>
<input tabindex="2" type="text" id="lastName" name="last_name" maxLength="150" class="form-control"
value="<?= old('last_name', $user->last_name) ?>">
<div class="row">
<div class="col-md-6 col-lg-6">
<div class="mb-3">
<label for="status" class="form-label">
<?= lang('Users.blocked') ?>
</label>
<?php $isBanned = old('blocked', $user->status); ?>
<select tabindex="4" name="status" id="status" class="select2 form-control">
<option value="0" <?= is_null($isBanned) ? 'selected' : '' ?>><?= lang("Users.non_blocked") ?></option>
<option value="1" <?= $isBanned === "banned" ? 'selected' : '' ?>><?= lang("Users.blocked") ?></option>
</select>
</div>
</div>
<div class="mb-3">
<label for="status" class="form-label">
<?= lang('Users.blocked') ?>
</label>
<?php $isBanned = old('blocked', $user->status); ?>
<select tabindex="4" name="status" id="status" class="select2 form-control">
<option value="0" <?= is_null($isBanned) ? 'selected' : '' ?>><?= lang("Users.non_blocked") ?></option>
<option value="1" <?= $isBanned === "banned" ? 'selected' : '' ?>><?= lang("Users.blocked") ?></option>
</select>
<div class="col-md-6 col-lg-6">
<div class="mb-3">
<label for="active" class="form-label">
<?= lang('Users.status') ?>
</label>
<?php $isActive = old('status', $user->active); ?>
<select tabindex="6" name="active" id="active" class="select2 form-control">
<option value="1" <?= $isActive ? 'selected' : '' ?>><?= lang("Users.global_active") ?></option>
<option value="0" <?= $isActive ? '' : 'selected' ?>><?= lang("Users.global_inactive") ?></option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-6">
<div class="mb-3">
<label for="new_pwd" class="form-label">
<?= lang('Users.password') ?>
</label>
<input
tabindex="8"
type="text"
id="new_pwd"
name="new_pwd"
maxLength="50"
class="form-control"
placeholder="Introduzca contraseña para cambiarla"
value=""
>
</div>
</div>
<div class="mb-3">
<label for="active" class="form-label">
<?= lang('Users.status') ?>
</label>
<?php $isActive = old('status', $user->active); ?>
<select tabindex="6" name="active" id="active" class="select2 form-control">
<option value="1" <?= $isActive ? 'selected' : '' ?>><?= lang("Users.global_active") ?></option>
<option value="0" <?= $isActive ? '' : 'selected' ?>><?= lang("Users.global_inactive") ?></option>
</select>
<div class="col-md-6 col-lg-6">
<div class="mb-3">
<label for="new_pwd_confirm" class="form-label">
Repita <?= lang('Users.password') ?>
</label>
<input
tabindex="9"
type="text"
id="new_pwd_confirm"
name="new_pwd_confirm"
maxLength="50"
class="form-control"
placeholder="Repita la contraseña para cambiarla"
value=""
>
</div>
</div>
</div>
<div class="row">
<div class="mb-3">
<label for="password" class="form-label">
<?= lang('Users.password') ?>
<label for="comments" class="form-label">
Comentarios
</label>
<input
tabindex="8"
type="text"
id="password"
name="password"
maxLength="50"
<textarea
rows="3"
id="comments"
name="comments"
style="height: 10em;"
class="form-control"
placeholder="Introduzca contraseña para cambiarla"
value=""
>
><?=old('comments', $user->comments) ?></textarea>
</div>
</div>
</div><!--//.col -->
</div><!--//.col -->
</div><!-- //.row -->