diff --git a/ci4/app/Controllers/Profile.php b/ci4/app/Controllers/Profile.php index a8f3c8ae..2c0ce90d 100755 --- a/ci4/app/Controllers/Profile.php +++ b/ci4/app/Controllers/Profile.php @@ -30,165 +30,120 @@ class Profile extends BaseController $data['title'] = [ 'module' => lang("App.profile_title"), - 'page' => lang("App.profile_subtitle"), - 'icon' => 'fas fa-user' + '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] + ['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' + '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' + 'route' => '', + 'class' => 'btn btn-primary mr-1', + 'icon' => 'fas fa-save' ]; $session = session(); - $data['obj'] = $this->user_model->where('id_user',$this->id_user)->first(); + $data['obj'] = $this->user_model->where('id_user', $this->id_user)->first(); - if(!empty($data['obj']->date_birth)){ + if (!empty($data['obj']->date_birth)) { $data['obj']->date_birth = dateFormatWeb($data['obj']->date_birth); } - $data['country'] = $this->countries_model->select('code,name')->where('data_lang',session()->get('lang')??'en')->findAll(); + $data['country'] = $this->countries_model->select('code,name')->where('data_lang', session()->get('lang') ?? 'en')->findAll(); $file = $this->request->getFile('file'); - if(!empty($file)){ + if (!empty($file)) { $integration = new Integration(); - $allow = ['jpeg','jpg','gif','bmp','png']; + $allow = ['jpeg', 'jpg', 'gif', 'bmp', 'png']; $path = 'assets/img/'; - $pathRet = '/'.$integration->saveStorage($file,$path,$allow); - if(!empty($pathRet)){ + $pathRet = '/' . $integration->saveStorage($file, $path, $allow); + if (!empty($pathRet)) { $this->user_model->save([ 'id_user' => $this->id_user, 'picture' => $pathRet ]); $data['obj']['picture'] = $pathRet; - $session->set('picture',$pathRet); + $session->set('picture', $pathRet); } - }else{ - if(!empty($this->request->getPost())){ + } else { + if (!empty($this->request->getPost())) { $post = $this->request->getPost(); $image = ''; - foreach ($post as $key=>$value){ - if(strpos($key, 'image') !== false){ + foreach ($post as $key => $value) { + if (strpos($key, 'image') !== false) { $image = $value; } } - if(!empty($image)){ + if (!empty($image)) { $this->user_model->save([ 'id_user' => $this->id_user, 'picture' => $image ]); $data['obj']['picture'] = $image; - $session->set('picture',$image); + $session->set('picture', $image); } } } - echo view(getenv('theme.path').'form/profile/index', $data); + echo view(getenv('theme.path') . 'form/profile/index', $data); } public function store() { - //Demo Mode - if(env('demo.mode')??false){ - session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]); - return redirect()->to('/profile'); - } $session = session(); helper('form'); - $password = 'max_length[35]'; - $confirm_password = 'max_length[35]'; - - if(!empty($this->request->getPost('password'))){ - $password = 'required|min_length[8]'; - $confirm_password = 'matches[password]'; - } $rules = [ - 'first_name' => 'required', - 'last_name' => 'required', - 'password' => $password, - 'confirm_password' => $confirm_password + 'first_name' => 'required', + 'last_name' => 'required', ]; $rules_error = [ 'first_name' => ['required' => lang("App.profile_rules_first_name_r")], 'last_name' => ['required' => lang("App.profile_rules_last_name_r")], - 'password' => [ - 'required' => lang("App.profile_rules_password_r"), - 'min_length' => lang("App.profile_rules_password_m") - ], - 'confirm_password' => ['matches' => lang("App.profile_rules_password_confirm_m")] ]; - if(empty($this->request->getPost('tfa_secret'))){ - if ($this->validate($rules??[],$rules_error??[])){ - if(!empty($this->id_user)){ - $date_birth = !empty($this->request->getPost('date_birth')??'') ? dateFormatMysql($this->request->getPost('date_birth')):null; - $this->user_model->save([ - 'id_user' => $this->id_user, - 'first_name' => $this->request->getPost('first_name'), - 'last_name' => $this->request->getPost('last_name'), - 'date_birth' => $date_birth, - 'address' => $this->request->getPost('address'), - 'city' => $this->request->getPost('city'), - 'state' => $this->request->getPost('state'), - 'country' => $this->request->getPost('country'), - 'zip_code' => $this->request->getPost('zip_code'), - 'mobile' => $this->request->getPost('mobile'), - 'language' => $this->request->getPost('language') - ]); - $session->set('lang', $this->request->getPost('language') ?? 'en'); - if(!empty($this->request->getPost('password'))){ - $phpass = new PasswordHash(8, true); - $this->user_model->save([ - 'id_user' => $this->id_user, - 'password' => $phpass->HashPassword($this->request->getPost('password')), - ]); - } - $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(); - } - }else{ - if($this->request->getPost('tfa') == 'on'){ + if ($this->validate($rules ?? [], $rules_error ?? [])) { + if (!empty($this->id_user)) { $this->user_model->save([ 'id_user' => $this->id_user, - 'tfa' => true, - 'tfa_secret' => $this->request->getPost('tfa_secret'), - 'tfa_code' => $this->request->getPost('tfa_code') - ]); - }else{ - $this->user_model->save([ - 'id_user' => $this->id_user, - 'tfa' => false, - 'tfa_secret' => '', - 'tfa_code' => '' + 'first_name' => $this->request->getPost('first_name'), + 'last_name' => $this->request->getPost('last_name'), + 'address' => $this->request->getPost('address'), + 'city' => $this->request->getPost('city'), + 'state' => $this->request->getPost('state'), + 'country' => $this->request->getPost('country'), + 'mobile' => $this->request->getPost('mobile'), + 'language' => $this->request->getPost('language') ]); + $session->set('lang', $this->request->getPost('language') ?? 'en'); + $session->setFlashdata('sweet', ['success', lang("App.global_alert_save_success")]); + } else { + $session->setFlashdata('sweet', ['error', lang("App.global_alert_save_error")]); } - $session->setFlashdata('sweet', ['success',lang("App.global_alert_save_success")]); + } else { + + $session->setFlashdata('error', 'error'); + return $this->index(); } + + return redirect()->to('/profile'); } } diff --git a/ci4/app/Views/themes/backend/vuexy/form/profile/index.php b/ci4/app/Views/themes/backend/vuexy/form/profile/index.php index bdf468de..5dec8ad8 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/profile/index.php +++ b/ci4/app/Views/themes/backend/vuexy/form/profile/index.php @@ -88,20 +88,9 @@ value="= (isset($obj)) ? $obj->email : set_value('email'); ?>" /> -