diff --git a/ci4/app/Controllers/Profile.php b/ci4/app/Controllers/Profile.php index d18708e8..71772a74 100755 --- a/ci4/app/Controllers/Profile.php +++ b/ci4/app/Controllers/Profile.php @@ -7,52 +7,25 @@ use App\Models\UserModel; class Profile extends BaseController { - private $user_model; - private $id_user; - function __construct() { - $this->user_model = new UserModel(); - $this->id_user = auth()->user()->id; } public function index() { - helper('file'); - helper('form'); - helper('text'); - - $data['title'] = [ - 'module' => lang("App.profile_title"), - 'page' => lang("App.profile_subtitle"), - 'icon' => 'fas fa-user' - ]; $data['breadcrumb'] = [ ['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false], ['title' => lang("App.profile_title"), 'route' => "", 'active' => true] ]; - $data['btn_return'] = [ - 'title' => lang("App.global_come_back"), - 'route' => '/', - 'class' => 'btn btn-dark mr-1', - 'icon' => 'fas fa-angle-left' - ]; - - $data['btn_submit'] = [ - 'title' => lang("App.global_save"), - 'route' => '', - 'class' => 'btn btn-primary mr-1', - 'icon' => 'fas fa-save' - ]; - - $session = session(); - - $data['obj'] = $this->user_model->where('id', $this->id_user)->first(); + // Get the User Provider (UserModel by default) + $users = auth()->getProvider(); + // Find by the user_id + $data['obj'] = $users->findById(auth()->id()); echo view(getenv('theme.path') . 'form/profile/index', $data); @@ -60,38 +33,55 @@ class Profile extends BaseController public function store() { - $session = session(); helper('form'); $rules = [ 'first_name' => 'required', 'last_name' => 'required', + 'new_pwd' => 'permit_empty|min_length[8]', + 'new_pwd_confirm' => 'required_with[new_pwd]|matches[new_pwd]' ]; + // Definir los mensajes de error personalizados $rules_error = [ 'first_name' => ['required' => lang("App.profile_rules_first_name_r")], 'last_name' => ['required' => lang("App.profile_rules_last_name_r")], + 'new_pwd' => ['min_length' => lang("App.profile_rules_password_m")], + 'new_pwd_confirm' => [ + 'matches' => lang("App.profile_rules_password_confirm_m") + ] ]; - - if ($this->validate($rules ?? [], $rules_error ?? [])) { - if (!empty($this->id_user)) { - $this->user_model->save([ - 'id' => $this->id_user, - 'first_name' => $this->request->getPost('first_name'), - 'last_name' => $this->request->getPost('last_name') - ]); - $session->setFlashdata('sweet', ['success', lang("App.global_alert_save_success")]); - } else { - $session->setFlashdata('sweet', ['error', lang("App.global_alert_save_error")]); - } - } else { - - $session->setFlashdata('error', 'error'); - return $this->index(); + // Validar la entrada + if (!$this->validate($rules, $rules_error)) { + // Si la validación falla, redirigir de vuelta con errores + return redirect()->back()->withInput()->with('errors', $this->validator->getErrors()); } - return redirect()->to('/profile'); + // Obtener los valores de los campos + $firstName = $this->request->getPost('first_name'); + $lastName = $this->request->getPost('last_name'); + $newPwd = $this->request->getPost('new_pwd'); + + $update_data = [ + 'first_name' => $firstName, + 'last_name' => $lastName, + 'password' => $newPwd, + ]; + + if(empty($newPwd)){ + unset($update_data['password']); + } + + // Aquí debes obtener el usuario actual, por ejemplo, desde la sesión + $users = auth()->getProvider(); + $user = $users->findById(auth()->id()); + $user->fill($update_data); + $users->save($user); + + // Redirigir con un mensaje de éxito + return redirect()->back()->with('success', lang('App.profile_updated_successfully')); + } } diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 5e607b58..e03fa10d 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -137,9 +137,9 @@ return [ "profile_mobile" => "Teléfono Móvil", "profile_mobile_ph" => "Escriba su número de celular", "profile_password" => "Cambiar Contraseña", - "profile_password_ph" => "Escribe tu contraseña", - "profile_confirm_password" => "Confirmar seña", - "profile_confirm_password_ph" => "Confirma tu contraseña anterior", + "profile_password_ph" => "Escribe nueva contraseña para cambiarla", + "profile_confirm_password" => "Confirmar contraseña", + "profile_confirm_password_ph" => "Confirma tu contraseña anterior para cambiarla", "profile_date_birth" => "Fecha de Nacimiento", "profile_date_birth_ph" => "Seleccionar fecha de nacimiento", "profile_address" => "Dirección", diff --git a/ci4/app/Views/themes/vuexy/form/profile/index.php b/ci4/app/Views/themes/vuexy/form/profile/index.php index 58eee725..bff0c49f 100644 --- a/ci4/app/Views/themes/vuexy/form/profile/index.php +++ b/ci4/app/Views/themes/vuexy/form/profile/index.php @@ -1,4 +1,3 @@ -include("themes/_commonPartialsBs/select2bs5") ?> extend('themes/vuexy/main/general_settings_layout') ?> section('content'); ?> @@ -12,10 +11,11 @@
">
-
- +
+
-
- +
+
-
+
" value="email : set_value('email'); ?>" />
+
+ + " + value="" + /> +
+
+ + " + value="" + /> +
- - + + "btn btn-danger"]) ?>
@@ -96,12 +123,7 @@ section('additionalInlineJs') ?> "use strict"; $(document).ready(function () { -$('#first_name').focus(); + $('#first_name').focus(); }); -$('.file-upload').on('click', function (e) { -e.preventDefault(); -$('#file').trigger('click'); -}); - endSection() ?> diff --git a/ci4/app/Views/themes/vuexy/form/profile/index_old.php b/ci4/app/Views/themes/vuexy/form/profile/index_old.php deleted file mode 100644 index c0aadbd7..00000000 --- a/ci4/app/Views/themes/vuexy/form/profile/index_old.php +++ /dev/null @@ -1,444 +0,0 @@ - -" - rel="stylesheet"> - - -
-
-
-
-
-

- -
-
-
- -
-
-
-
-
-
-

-
-
- -
" method="post"> - -
-
-
- -
-
-
- - " - value="first_name : set_value('first_name'); ?>"> -
-
-
-
- - " - value="last_name : set_value('last_name'); ?>"> -
-
-
-
- - " - id="date_birth" name="date_birth" - value="date_birth : set_value('date_birth'); ?>"> -
-
-
-
- - " - value="email : set_value('email'); ?>" - disabled> -
-
-
-
- - " - value="mobile : set_value('mobile'); ?>"> -
-
-
-
- - "> -
-
-
-
- - "> -
-
-
-
-
- -
-
-
- - " - value="address : set_value('address'); ?>"> -
-
-
-
- - " - value="city : set_value('city'); ?>"> -
-
-
-
- - " - value="state : set_value('state'); ?>"> -
-
-
-
- - country ?? [] : set_value('country'); ?> - -
-
-
-
- - language ?? [] : set_value('language'); ?> - -
-
-
-
-
- - - - -
-
-
-
-
-
-
-
-

-
-
-
-
- -
-
- first_name ?? '' ?>
- email ?? '' ?> -
-
- -
- - -
-
-
-
-
- get('settings'); ?> - - -
" method="post" id="sendFormTFA"> - -
-
-
-
-
-
-

-
-
-
- > - -
-
-
-
-
-
- GetQR("{$settings['title']} ({$name})", $tfa_secret); - } else { - $tfa_secret = $tfa->createSecret(); - $qrcode = $tfa->GetQR("{$settings['title']} ({$name})", $tfa_secret); - } - ?> -
-
-

- -
-
-

- ' . $item . ''; - } - } else { - $codes = array(); - for ($i = 1; $i <= 8; $i++) { - $code = random_string('numeric', 6); - $codes[] = $code; - echo '' . $code . ''; - } - } - ?> -


- - - -
-
-
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - -