Actualizacion automatica: 2024-11-18 16:05:01

This commit is contained in:
imnavajas
2024-11-18 16:05:01 +01:00
parent 5fbfe97a59
commit 006a9a1413
5 changed files with 28 additions and 19 deletions

View File

@ -245,6 +245,7 @@ class Auth extends ShieldAuth
'required', 'required',
'max_length[254]', 'max_length[254]',
'valid_email', 'valid_email',
'is_unique[auth_identities.secret]',
], ],
]; ];

View File

@ -34,7 +34,7 @@ class Validation extends BaseConfig
* @var array<string, string> * @var array<string, string>
*/ */
public array $templates = [ public array $templates = [
'list' => 'CodeIgniter\Validation\Views\list', 'list' => 'CodeIgniter\Validation\Views\list',
'single' => 'CodeIgniter\Validation\Views\single', 'single' => 'CodeIgniter\Validation\Views\single',
'bootstrap_style' => 'themes/_commonPartialsBs/_form_validation_errors', 'bootstrap_style' => 'themes/_commonPartialsBs/_form_validation_errors',
]; ];
@ -42,4 +42,6 @@ class Validation extends BaseConfig
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Rules // Rules
// -------------------------------------------------------------------- // --------------------------------------------------------------------
} }

View File

@ -20,7 +20,6 @@ class Users extends \App\Controllers\GoBaseController
private ChatDeparmentUserModel $chat_department_user_model; private ChatDeparmentUserModel $chat_department_user_model;
use \CodeIgniter\API\ResponseTrait; use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\UserModel'; protected static $primaryModelName = 'App\Models\UserModel';
@ -62,7 +61,7 @@ class Users extends \App\Controllers\GoBaseController
$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();
} }
@ -77,17 +76,18 @@ class Users extends \App\Controllers\GoBaseController
// 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['new_pwd'])) { if (empty($postData['new_pwd'])) {
$postData['password'] = 'Safekat2024'; // Contraseña por defecto $postData['password'] = 'Safekat2024'; // Contraseña por defecto
}else{ } else {
$postData['password'] = $postData['new_pwd']; $postData['password'] = $postData['new_pwd'];
} }
// Obtener los grupos a los que pertenece // Obtener los grupos a los que pertenece
$currentGroups = $postData['group'] ?? []; $currentGroups = $postData['group'] ?? [];
$chatDepartments = $postData['chatDepartments'] ?? []; $chatDepartments = $postData['chatDepartments'] ?? [];
unset($postData['group']); unset($postData['group']);
unset($postData['chatDepartments']); unset($postData['chatDepartments']);
// Generar el nombre de usuario // Marcar el username como NULL
$postData['username'] = strstr($postData['email'], '@', true); $postData['username'] = null;
$sanitizedData = $this->sanitized($postData, true); $sanitizedData = $this->sanitized($postData, true);
$noException = true; $noException = true;
@ -99,6 +99,7 @@ class Users extends \App\Controllers\GoBaseController
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
// Crear el usuario si pasa la validación
$user = new User([ $user = new User([
'username' => $sanitizedData['username'], 'username' => $sanitizedData['username'],
'first_name' => $sanitizedData['first_name'], 'first_name' => $sanitizedData['first_name'],
@ -110,6 +111,7 @@ class Users extends \App\Controllers\GoBaseController
]); ]);
$users->save($user); $users->save($user);
$successfulResult = true; // Hacked $successfulResult = true; // Hacked
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
//$this->dealWithException($e); //$this->dealWithException($e);
@ -137,12 +139,11 @@ class Users extends \App\Controllers\GoBaseController
]; ];
$this->group_user_model->insert($group_user_data); $this->group_user_model->insert($group_user_data);
} }
$this->chat_department_user_model->where("user_id",$id)->delete(); $this->chat_department_user_model->where("user_id", $id)->delete();
foreach($chatDepartments as $chatDepartment) foreach ($chatDepartments as $chatDepartment) {
{
$this->chat_department_user_model->insert([ $this->chat_department_user_model->insert([
"user_id" => $id, "user_id" => $id,
"chat_department_id" => $this->chat_department_model->where("name",$chatDepartment)->first()["id"] "chat_department_id" => $this->chat_department_model->where("name", $chatDepartment)->first()["id"]
]); ]);
} }
@ -199,7 +200,6 @@ class Users extends \App\Controllers\GoBaseController
unset($postData['group']); unset($postData['group']);
unset($postData['chatDepartments']); unset($postData['chatDepartments']);
// Obtener contraseña nueva si se ha introducido en texto plano
// 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['new_pwd'])) { if (!empty($postData['new_pwd'])) {
$postData['password'] = $postData['new_pwd']; $postData['password'] = $postData['new_pwd'];
@ -254,12 +254,11 @@ class Users extends \App\Controllers\GoBaseController
]; ];
$this->group_user_model->insert($group_user_data); $this->group_user_model->insert($group_user_data);
} }
$this->chat_department_user_model->where("user_id",$id)->delete(); $this->chat_department_user_model->where("user_id", $id)->delete();
foreach($chatDepartments as $chatDepartment) foreach ($chatDepartments as $chatDepartment) {
{
$this->chat_department_user_model->insert([ $this->chat_department_user_model->insert([
"user_id" => $id, "user_id" => $id,
"chat_department_id" => $this->chat_department_model->where("name",$chatDepartment)->first()["id"] "chat_department_id" => $this->chat_department_model->where("name", $chatDepartment)->first()["id"]
]); ]);
} }
$id = $user->id ?? $id; $id = $user->id ?? $id;
@ -284,7 +283,7 @@ class Users extends \App\Controllers\GoBaseController
$this->viewData['formAction'] = route_to('updateUser', $id); $this->viewData['formAction'] = route_to('updateUser', $id);
$this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId); $this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId);
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
$this->viewData['chatDepartments'] = $this->chat_department_model->select(["display","name","id as chatDepartmentId"])->findAll(); $this->viewData['chatDepartments'] = $this->chat_department_model->select(["display", "name", "id as chatDepartmentId"])->findAll();
$this->viewData['chatDepartmentUser'] = $this->chat_department_user_model->getChatDepartmentUser($user->id); $this->viewData['chatDepartmentUser'] = $this->chat_department_user_model->getChatDepartmentUser($user->id);
$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');
@ -308,7 +307,7 @@ class Users extends \App\Controllers\GoBaseController
endif; endif;
$users = auth()->getProvider(); $users = auth()->getProvider();
$users->delete($user->id); $users->delete($user->id, true);
$message = "Usuario eliminado correctamente"; $message = "Usuario eliminado correctamente";
return $this->redirect2listView('successMessage', $message); return $this->redirect2listView('successMessage', $message);

View File

@ -15,7 +15,7 @@ return [
'createdAt' => 'Created At', 'createdAt' => 'Created At',
'dateBirth' => 'Date Birth', 'dateBirth' => 'Date Birth',
'email' => 'Email', 'email' => 'Email',
'emailConfirmed' => 'Email Confirmed', 'emailConfirmed' => 'Email Confirmed',
'firstName' => 'First Name', 'firstName' => 'First Name',
'group' => 'Group', 'group' => 'Group',
'idUser' => 'ID User', 'idUser' => 'ID User',

View File

@ -36,7 +36,8 @@ class UserModel extends ShieldUserModel
"last_name" => "required|trim|max_length[150]", "last_name" => "required|trim|max_length[150]",
'new_pwd' => 'permit_empty|min_length[8]', 'new_pwd' => 'permit_empty|min_length[8]',
'new_pwd_confirm' => 'permit_empty|required_with[new_pwd]|matches[new_pwd]', 'new_pwd_confirm' => 'permit_empty|required_with[new_pwd]|matches[new_pwd]',
"comments" => "permit_empty|trim|max_length[512]" "comments" => "permit_empty|trim|max_length[512]",
'email' => 'required|valid_email|is_unique[auth_identities.secret]',
]; ];
protected $validationMessages = [ protected $validationMessages = [
@ -77,5 +78,11 @@ class UserModel extends ShieldUserModel
} }
// Método para comprobar si el email ya está registrado
public function isEmailUnique($email)
{
return $this->where('email', $email)->countAllResults() == 0;
}
} }