mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
98 lines
2.5 KiB
PHP
Executable File
98 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
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();
|
|
|
|
|
|
echo view(getenv('theme.path') . 'form/profile/index', $data);
|
|
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
|
|
$session = session();
|
|
helper('form');
|
|
|
|
$rules = [
|
|
'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")],
|
|
];
|
|
|
|
|
|
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();
|
|
}
|
|
|
|
return redirect()->to('/profile');
|
|
}
|
|
}
|