mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Actualizacion automatica: 2024-11-18 16:05:01
This commit is contained in:
@ -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]',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -42,4 +42,6 @@ class Validation extends BaseConfig
|
|||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// Rules
|
// Rules
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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';
|
||||||
@ -80,14 +79,15 @@ class Users extends \App\Controllers\GoBaseController
|
|||||||
} 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);
|
||||||
@ -138,8 +140,7 @@ 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'];
|
||||||
@ -255,8 +255,7 @@ 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"]
|
||||||
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user