mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Arreglando profile y pequeños bugs
This commit is contained in:
@ -2,24 +2,20 @@
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\PasswordHash;
|
||||
use App\Models\CountriesModel;
|
||||
use App\Models\UserGroupModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Profile extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $countries_model;
|
||||
private $id_user;
|
||||
private $token_user;
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->countries_model = new CountriesModel();
|
||||
$this->id_user = session()->get('id_user');
|
||||
$this->token_user = session()->get('token');
|
||||
$this->id_user = auth()->user()->id;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
@ -55,46 +51,8 @@ class Profile extends BaseController
|
||||
|
||||
$session = session();
|
||||
|
||||
$data['obj'] = $this->user_model->where('id_user', $this->id_user)->first();
|
||||
$data['obj'] = $this->user_model->where('id', $this->id_user)->first();
|
||||
|
||||
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();
|
||||
|
||||
$file = $this->request->getFile('file');
|
||||
if (!empty($file)) {
|
||||
$integration = new Integration();
|
||||
$allow = ['jpeg', 'jpg', 'gif', 'bmp', 'png'];
|
||||
$path = 'assets/img/';
|
||||
$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);
|
||||
}
|
||||
} else {
|
||||
if (!empty($this->request->getPost())) {
|
||||
$post = $this->request->getPost();
|
||||
$image = '';
|
||||
foreach ($post as $key => $value) {
|
||||
if (strpos($key, 'image') !== false) {
|
||||
$image = $value;
|
||||
}
|
||||
}
|
||||
if (!empty($image)) {
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'picture' => $image
|
||||
]);
|
||||
$data['obj']['picture'] = $image;
|
||||
$session->set('picture', $image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo view(getenv('theme.path') . 'form/profile/index', $data);
|
||||
|
||||
@ -103,11 +61,9 @@ class Profile extends BaseController
|
||||
public function store()
|
||||
{
|
||||
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
|
||||
$rules = [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
@ -122,17 +78,10 @@ class Profile extends BaseController
|
||||
if ($this->validate($rules ?? [], $rules_error ?? [])) {
|
||||
if (!empty($this->id_user)) {
|
||||
$this->user_model->save([
|
||||
'id_user' => $this->id_user,
|
||||
'id' => $this->id_user,
|
||||
'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')
|
||||
'last_name' => $this->request->getPost('last_name')
|
||||
]);
|
||||
$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")]);
|
||||
@ -143,7 +92,6 @@ class Profile extends BaseController
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
|
||||
return redirect()->to('/profile');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user