mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'mod/user_pwd' into 'main'
Añadido campo de verficacion de contraseña y campo de notas See merge request jjimenez/safekat!291
This commit is contained in:
@ -53,15 +53,12 @@ class Users extends \App\Controllers\GoBaseController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->viewData['usingClientSideDataTable'] = true;
|
$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['user_model'] = $this->user_model;
|
||||||
|
|
||||||
$this->viewData['userList2'] = auth()->getProvider()->findAll();
|
$this->viewData['userList2'] = auth()->getProvider()->findAll();
|
||||||
|
|
||||||
parent::index();
|
parent::index();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add()
|
public function add()
|
||||||
@ -72,21 +69,24 @@ class Users extends \App\Controllers\GoBaseController
|
|||||||
$postData = $this->request->getPost();
|
$postData = $this->request->getPost();
|
||||||
|
|
||||||
// Obtener contraseña nueva si se ha introducido en texto plano
|
// 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
|
$postData['password'] = 'Safekat2024'; // Contraseña por defecto
|
||||||
|
}else{
|
||||||
|
$postData['password'] = $postData['new_pwd'];
|
||||||
}
|
}
|
||||||
|
// Obtener los grupos a los que pertenece
|
||||||
$currentGroups = $postData['group'] ?? [];
|
$currentGroups = $postData['group'] ?? [];
|
||||||
unset($postData['group']);
|
unset($postData['group']);
|
||||||
|
// Generar el nombre de usuario
|
||||||
$postData['username'] = strstr($postData['email'], '@', true);
|
$postData['username'] = strstr($postData['email'], '@', true);
|
||||||
$sanitizedData = $this->sanitized($postData, true);
|
$sanitizedData = $this->sanitized($postData, true);
|
||||||
|
|
||||||
$noException = true;
|
$noException = true;
|
||||||
|
|
||||||
|
// Obtener proveedor de usuarios
|
||||||
$users = auth()->getProvider();
|
$users = auth()->getProvider();
|
||||||
|
|
||||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
if ($successfulResult = $this->canValidate()) :
|
||||||
if ($this->canValidate()) :
|
if ($this->canValidate()) :
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -179,8 +179,9 @@ class Users extends \App\Controllers\GoBaseController
|
|||||||
unset($postData['group']);
|
unset($postData['group']);
|
||||||
|
|
||||||
// Obtener contraseña nueva si se ha introducido en texto plano
|
// Obtener contraseña nueva si se ha introducido en texto plano
|
||||||
if (empty($postData['password'])) {
|
// Obtener contraseña nueva si se ha introducido en texto plano
|
||||||
unset($postData['password']);
|
if (!empty($postData['new_pwd'])) {
|
||||||
|
$postData['password'] = $postData['new_pwd'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$sanitizedData = $this->sanitized($postData, true);
|
$sanitizedData = $this->sanitized($postData, true);
|
||||||
|
|||||||
@ -6,11 +6,13 @@ use CodeIgniter\Shield\Entities\User;
|
|||||||
class UsersEntity extends User
|
class UsersEntity extends User
|
||||||
{
|
{
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
"first_name" => null,
|
'first_name' => null,
|
||||||
"last_name" => null
|
'last_name'=> null,
|
||||||
|
'cliente_id' => null,
|
||||||
|
'comments' => null,
|
||||||
];
|
];
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
"cliente_id" => "int",
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getFullName()
|
public function getFullName()
|
||||||
|
|||||||
@ -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' => [
|
'email' => [
|
||||||
'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.',
|
'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.',
|
||||||
'required' => 'El campo {field} es obligatorio.',
|
'required' => 'El campo {field} es obligatorio.',
|
||||||
|
|||||||
@ -18,6 +18,7 @@ class UserModel extends ShieldUserModel
|
|||||||
'first_name', // Añadido
|
'first_name', // Añadido
|
||||||
'last_name', // Añadido
|
'last_name', // Añadido
|
||||||
'cliente_id', // Añadido
|
'cliente_id', // Añadido
|
||||||
|
'comments', // Añadido
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,19 +28,41 @@ class UserModel extends ShieldUserModel
|
|||||||
protected $useTimestamps = true;
|
protected $useTimestamps = true;
|
||||||
protected $createdField = 'created_at';
|
protected $createdField = 'created_at';
|
||||||
protected $updatedField = 'updated_at';
|
protected $updatedField = 'updated_at';
|
||||||
protected $deletedField = 'deleted_at';
|
protected $deletedField = 'deleted_at';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected $validationRules = [
|
protected $validationRules = [
|
||||||
"username" => [
|
"first_name" => "required|trim|max_length[150]",
|
||||||
"label" => "correo duplicado",
|
"last_name" => "required|trim|max_length[150]",
|
||||||
"rules" => "is_unique[users.username]",
|
'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
|
$builder = $this->db
|
||||||
->table("users" . " t1")
|
->table("users" . " t1")
|
||||||
->select(
|
->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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,37 @@
|
|||||||
<div class="row">
|
<div class="col-md-12 col-lg-12 px-4">
|
||||||
<div class="col-md-12 col-lg-6 px-4">
|
<div class="row">
|
||||||
<div class="mb-3">
|
<div class="col-md-6 col-lg-4">
|
||||||
<label for="firstName" class="form-label">
|
<div class="mb-3">
|
||||||
<?= lang('Users.firstName') ?>
|
<label for="firstName" class="form-label">
|
||||||
</label>
|
<?= lang('Users.firstName') ?> *
|
||||||
<input tabindex="1" type="text" id="firstName" name="first_name" maxLength="150" class="form-control"
|
</label>
|
||||||
value="<?= old('first_name', $user->first_name) ?>">
|
<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>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="col-md-6 col-lg-4">
|
||||||
<label for="email" class="form-label">
|
<div class="mb-3">
|
||||||
<?= lang('Users.email') ?>*
|
<label for="lastName" class="form-label">
|
||||||
</label>
|
<?= lang('Users.lastName') ?> *
|
||||||
<input tabindex="3" type="email" id="email" name="email" maxLength="150" class="form-control"
|
</label>
|
||||||
value="<?= old('email', $user->email) ?>">
|
<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>
|
||||||
|
|
||||||
|
<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="mb-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="group" class="form-label"> <?= lang('Users.group') ?></label>
|
<label for="group" class="form-label"> <?= lang('Users.group') ?></label>
|
||||||
@ -36,7 +52,6 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="cliente_id" class="form-label">
|
<label for="cliente_id" class="form-label">
|
||||||
<?= lang('Presupuestos.clienteId') ?>
|
<?= lang('Presupuestos.clienteId') ?>
|
||||||
@ -52,59 +67,90 @@
|
|||||||
endif; ?>
|
endif; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
</div><!--//.col -->
|
<div class="col-md-6 col-lg-6">
|
||||||
|
<div class="mb-3">
|
||||||
<div class="col-md-12 col-lg-6 px-4">
|
<label for="status" class="form-label">
|
||||||
|
<?= lang('Users.blocked') ?>
|
||||||
<div class="mb-3">
|
</label>
|
||||||
<label for="lastName" class="form-label">
|
<?php $isBanned = old('blocked', $user->status); ?>
|
||||||
<?= lang('Users.lastName') ?>
|
<select tabindex="4" name="status" id="status" class="select2 form-control">
|
||||||
</label>
|
<option value="0" <?= is_null($isBanned) ? 'selected' : '' ?>><?= lang("Users.non_blocked") ?></option>
|
||||||
<input tabindex="2" type="text" id="lastName" name="last_name" maxLength="150" class="form-control"
|
<option value="1" <?= $isBanned === "banned" ? 'selected' : '' ?>><?= lang("Users.blocked") ?></option>
|
||||||
value="<?= old('last_name', $user->last_name) ?>">
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="col-md-6 col-lg-6">
|
||||||
<label for="status" class="form-label">
|
<div class="mb-3">
|
||||||
<?= lang('Users.blocked') ?>
|
<label for="active" class="form-label">
|
||||||
</label>
|
<?= lang('Users.status') ?>
|
||||||
<?php $isBanned = old('blocked', $user->status); ?>
|
</label>
|
||||||
<select tabindex="4" name="status" id="status" class="select2 form-control">
|
<?php $isActive = old('status', $user->active); ?>
|
||||||
<option value="0" <?= is_null($isBanned) ? 'selected' : '' ?>><?= lang("Users.non_blocked") ?></option>
|
<select tabindex="6" name="active" id="active" class="select2 form-control">
|
||||||
<option value="1" <?= $isBanned === "banned" ? 'selected' : '' ?>><?= lang("Users.blocked") ?></option>
|
<option value="1" <?= $isActive ? 'selected' : '' ?>><?= lang("Users.global_active") ?></option>
|
||||||
</select>
|
<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>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="col-md-6 col-lg-6">
|
||||||
<label for="active" class="form-label">
|
<div class="mb-3">
|
||||||
<?= lang('Users.status') ?>
|
<label for="new_pwd_confirm" class="form-label">
|
||||||
</label>
|
Repita <?= lang('Users.password') ?>
|
||||||
<?php $isActive = old('status', $user->active); ?>
|
</label>
|
||||||
<select tabindex="6" name="active" id="active" class="select2 form-control">
|
<input
|
||||||
<option value="1" <?= $isActive ? 'selected' : '' ?>><?= lang("Users.global_active") ?></option>
|
tabindex="9"
|
||||||
<option value="0" <?= $isActive ? '' : 'selected' ?>><?= lang("Users.global_inactive") ?></option>
|
type="text"
|
||||||
</select>
|
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>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="password" class="form-label">
|
<label for="comments" class="form-label">
|
||||||
<?= lang('Users.password') ?>
|
Comentarios
|
||||||
</label>
|
</label>
|
||||||
<input
|
<textarea
|
||||||
tabindex="8"
|
rows="3"
|
||||||
type="text"
|
id="comments"
|
||||||
id="password"
|
name="comments"
|
||||||
name="password"
|
style="height: 10em;"
|
||||||
maxLength="50"
|
|
||||||
class="form-control"
|
class="form-control"
|
||||||
placeholder="Introduzca contraseña para cambiarla"
|
><?=old('comments', $user->comments) ?></textarea>
|
||||||
value=""
|
|
||||||
>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div><!--//.col -->
|
||||||
|
|
||||||
|
|
||||||
</div><!--//.col -->
|
|
||||||
|
|
||||||
</div><!-- //.row -->
|
|
||||||
Reference in New Issue
Block a user