mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Arreglado bug añadir usuarios con email repetido
This commit is contained in:
@ -87,7 +87,6 @@ class Users extends \App\Controllers\GoBaseController
|
||||
unset($postData['chatDepartments']);
|
||||
|
||||
// Marcar el username como NULL
|
||||
$postData['username'] = null;
|
||||
$sanitizedData = $this->sanitized($postData, true);
|
||||
|
||||
$noException = true;
|
||||
@ -99,35 +98,43 @@ class Users extends \App\Controllers\GoBaseController
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
|
||||
// Crear el usuario si pasa la validación
|
||||
$user = new User([
|
||||
'username' => $sanitizedData['username'],
|
||||
'first_name' => $sanitizedData['first_name'],
|
||||
'last_name' => $sanitizedData['last_name'],
|
||||
'email' => $sanitizedData['email'],
|
||||
'password' => $sanitizedData['password'],
|
||||
'status' => $sanitizedData['status'] ?? 0,
|
||||
'active' => $sanitizedData['active'] ?? 0,
|
||||
]);
|
||||
$users->save($user);
|
||||
$successfulResult = true; // Hacked
|
||||
// The Email is unique
|
||||
if ($this->user_model->isEmailUnique($sanitizedData['email'])) {
|
||||
|
||||
// Crear el usuario si pasa la validación
|
||||
$user = new \CodeIgniter\Shield\Entities\User([
|
||||
'username' => null, // If you don't have a username, be sure to set the value to null anyway, so that it passes CodeIgniter's empty data check
|
||||
'first_name' => $sanitizedData['first_name'],
|
||||
'last_name' => $sanitizedData['last_name'],
|
||||
'cliente_id' => $sanitizedData['cliente_id'],
|
||||
'comments' => $sanitizedData['comments'],
|
||||
'email' => $sanitizedData['email'],
|
||||
'password' => $sanitizedData['password'],
|
||||
'status' => $sanitizedData['status'] ?? 0,
|
||||
'active' => $sanitizedData['active'] ?? 0,
|
||||
]);
|
||||
// Add the user to the system
|
||||
$users->save($user);
|
||||
$successfulResult = true; // Hacked
|
||||
|
||||
} // Email is not unique!
|
||||
else {
|
||||
$this->viewData['errorMessage'] = "El correo '". $sanitizedData['email'] ."' ya está registrado en el sistema";
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
$successfulResult = false; // Hacked
|
||||
}
|
||||
|
||||
} 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());
|
||||
}
|
||||
|
||||
$this->viewData['errorMessage'] = $e->getMessage();
|
||||
}
|
||||
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;
|
||||
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $users->getInsertID();
|
||||
|
||||
Reference in New Issue
Block a user