Añadido cambio de contraseña en perfil de usuario (mejorar UI

This commit is contained in:
imnavajas
2024-07-15 23:20:00 +02:00
parent ce7ba82bda
commit ad26a70aed
5 changed files with 183 additions and 600 deletions

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Entities\Usuarios\UserEntity;
@ -8,15 +8,17 @@ use App\Models\Usuarios\GroupModel;
use App\Models\UserModel;
use App\Models\Usuarios\GroupsUsersModel;
use CodeIgniter\Shield\Entities\User;
use function PHPUnit\Framework\isNull;
class Users extends \App\Controllers\GoBaseController {
class Users extends \App\Controllers\GoBaseController
{
private $group_model;
private $group_user_model;
private $user_model;
use \CodeIgniter\API\ResponseTrait;
use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\UserModel';
@ -29,9 +31,9 @@ class Users extends \App\Controllers\GoBaseController {
protected $indexRoute = 'userList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->group_model = new GroupModel();
$this->group_user_model = new GroupsUsersModel();
@ -46,31 +48,39 @@ class Users extends \App\Controllers\GoBaseController {
];
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]);
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]);
$this->viewData['user_model'] = $this->user_model;
$this->viewData['userList2'] = $this->user_model->getUsersList();
$this->viewData['userList2'] = auth()->getProvider()->findAll();
parent::index();
}
public function add() {
public function add()
{
if ($this->request->getPost()) :
$postData = $this->request->getPost();
$currentGroups = $postData['group']??[];
// Obtener contraseña nueva si se ha introducido en texto plano
if (empty($postData['password'])) {
$postData['password'] = 'Safekat2024'; // Contraseña por defecto
}
$currentGroups = $postData['group'] ?? [];
unset($postData['group']);
$postData['username'] = strstr($postData['email'], '@', true);
$sanitizedData = $this->sanitized($postData, true);
$sanitizedData = $this->sanitized($postData, true);
$noException = true;
@ -78,40 +88,40 @@ class Users extends \App\Controllers\GoBaseController {
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
try {
$user = new User([
'username' => $sanitizedData['username'],
'first_name' => $sanitizedData['first_name'],
'last_name' => $sanitizedData['last_name'],
'email' => $sanitizedData['email'],
'password' => 'Safekat2024',
'status' => $sanitizedData['status']??0,
'active' => $sanitizedData['active']??0,
'email' => $sanitizedData['email'],
'password' => $sanitizedData['password'],
'status' => $sanitizedData['status'] ?? 0,
'active' => $sanitizedData['active'] ?? 0,
]);
$users->save($user);
$successfulResult = true; // Hacked
} catch (\Exception $e) {
$noException = false;
//$this->dealWithException($e);
} catch (\Exception $e) {
$noException = false;
//$this->dealWithException($e);
if (strpos($e->getMessage(), 'correo duplicado') !== false) {
$this->viewData['errorMessage'] = "El correo electrónico ya está registrado en el sistema";
$this->session->setFlashdata('formErrors', $this->model->errors());
}
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif;
if ($noException && $successfulResult) :
$id = $users->getInsertID();
$this->group_user_model->where('user_id', $id)->delete();
foreach($currentGroups as $group){
foreach ($currentGroups as $group) {
$group_user_data = [
'user_id' => $id,
'group' => $group
@ -119,8 +129,7 @@ class Users extends \App\Controllers\GoBaseController {
$this->group_user_model->insert($group_user_data);
}
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Users.user'))]) . 'Downloads';
$message .= anchor(route_to('editUser', $id), lang('Basic.global.continueEditing').'?');
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Users.user'))]) . '.';
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) :
@ -141,88 +150,91 @@ class Users extends \App\Controllers\GoBaseController {
$this->viewData['clienteList'] = $this->getClienteListItems();
$this->viewData['formAction'] = route_to('createUser');
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
$this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix');
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . lang('Users.user') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__);
} // end function add()
public function edit($requestedId = null) {
if ($requestedId == null) :
public function edit($requestedId = null)
{
if ($requestedId == null) {
return $this->redirect2listView();
endif;
}
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$user = $this->model->find($id);
$users = auth()->getProvider();
$user = $users->findById($id);
if ($user == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Users.user')), $id]);
return $this->redirect2listView('errorMessage', $message);
endif;
if ($this->request->getPost()) :
$postData = $this->request->getPost();
$currentGroups = $postData['group'];
$currentGroups = $postData['group'] ?? [];
unset($postData['group']);
// Obtener contraseña nueva si se ha introducido en texto plano
if (empty($postData['password'])) {
unset($postData['password']);
}
$sanitizedData = $this->sanitized($postData, true);
if ($this->request->getPost('status') == 0 ) {
if ($this->request->getPost('status') == 0) {
$sanitizedData['status'] = null;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($successfulResult = $this->canValidate()) :
if ($this->canValidate()) :
try {
if ($this->canValidate()) :
try {
if (in_array('cliente-editor', $currentGroups) || in_array('cliente-administrador', $currentGroups)) {
if(!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) {
if (!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) {
$this->viewData['errorMessage'] = lang('Users.errors.cliente_sin_clienteID');
$this->session->setFlashdata('formErrors', $this->model->errors());
$successfulResult = false;
} else {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
}
else{
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
}
}
else {
} else {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
}
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
$user->fill($sanitizedData);
$thenRedirect = false;
endif;
$user->fill($sanitizedData);
$users->save($user);
$thenRedirect = false;
endif;
if ($noException && $successfulResult) :
$this->group_user_model->where('user_id', $user->id)->delete();
foreach($currentGroups as $group){
foreach ($currentGroups as $group) {
$group_user_data = [
'user_id' => $user->id,
'group' => $group
];
$this->group_user_model->insert($group_user_data);
}
$id = $user->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Users.user'))]) . 'Downloads';
$message .= anchor(route_to('editUser', $id), lang('Basic.global.continueEditing').'?');
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Users.user'))]) . '.';
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) :
@ -234,7 +246,7 @@ class Users extends \App\Controllers\GoBaseController {
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
@ -243,13 +255,14 @@ class Users extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('updateUser', $id);
$this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId);
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
$this->viewData['boxTitle'] = lang('Basic.global.edit2') .lang('Users.user').' '.lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Users.user') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id);
} // end function edit(...)
public function delete($requestedId = null, bool $deletePermanently = true) {
public function delete($requestedId = null, bool $deletePermanently = true)
{
if ($requestedId == null) :
return $this->redirect2listView();
@ -264,26 +277,25 @@ class Users extends \App\Controllers\GoBaseController {
endif;
$users = auth()->getProvider();
$users->delete($user->id, $deletePermanently);
$users->delete($user->id);
$message = "Usuario eliminado correctamente";
return $this->redirect2listView('successMessage', $message);
} // end function delete(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id_user';
$menu = $this->model->getAllForMenu($reqVal.', first_name', 'first_name', $onlyActiveOnes, false);
$menu = $this->model->getAllForMenu($reqVal . ', first_name', 'first_name', $onlyActiveOnes, false);
$nonItem = new \stdClass;
$nonItem->id_user = '';
$nonItem->first_name = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->first_name = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -296,8 +308,9 @@ class Users extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0];
@ -308,8 +321,8 @@ class Users extends \App\Controllers\GoBaseController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -323,10 +336,11 @@ class Users extends \App\Controllers\GoBaseController {
}
}
public function getMenuComerciales(){
public function getMenuComerciales()
{
if ($this->request->isAJAX()) {
$comerciales = $this->model->getComerciales();
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
@ -339,15 +353,16 @@ class Users extends \App\Controllers\GoBaseController {
}
}
protected function getPaisListItems() {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])];
protected function getPaisListItems()
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])];
$paisModel = model('App\Models\Configuracion\PaisModel');
$registers = $paisModel->findAll();
return $registers;
}
return $registers;
}
protected function getClienteListItems($selId = null)
{
@ -362,5 +377,5 @@ class Users extends \App\Controllers\GoBaseController {
endif;
return $data;
}
}

View File

@ -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'));
}
}

View File

@ -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",

View File

@ -1,4 +1,3 @@
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
<?= $this->extend('themes/vuexy/main/general_settings_layout') ?>
<?= $this->section('content'); ?>
@ -12,10 +11,11 @@
<form id="formAccountSettings" method="POST" action="<?= site_url("profile/store") ?>">
<?= csrf_field() ?>
<div class="row">
<div class="mb-3 col-md-6">
<label for="first_name" class="form-label"><?= lang("App.profile_first_name") ?></label>
<div class="mb-3 col-md-4">
<label for="first_name" class="form-label"><?= lang("App.profile_first_name") ?> *</label>
<input
class="form-control"
tabindex="1"
type="text"
id="first_name"
name="first_name"
@ -24,9 +24,10 @@
autofocus
/>
</div>
<div class="mb-3 col-md-6">
<label for="last_name" class="form-label"><?= lang("App.profile_last_name") ?></label>
<div class="mb-3 col-md-4">
<label for="last_name" class="form-label"><?= lang("App.profile_last_name") ?> *</label>
<input class="form-control"
tabindex="2"
type="text"
name="last_name"
id="last_name"
@ -34,21 +35,47 @@
value="<?= (isset($obj)) ? $obj->last_name : set_value('last_name'); ?>"
/>
</div>
<div class="mb-3 col-md-6">
<div class="mb-3 col-md-4">
<label for="email" class="form-label"><?= lang("App.profile_email") ?></label>
<input
class="form-control"
tabindex="3"
type="text"
id="email"
name="email"
disabled
placeholder="<?= lang("App.profile_email_ph") ?>"
value="<?= (isset($obj)) ? $obj->email : set_value('email'); ?>"
/>
</div>
<div class="mb-3 col-md-6">
<label for="new_pwd" class="form-label"><?= lang("App.profile_password") ?></label>
<input
class="form-control"
tabindex="4"
type="text"
id="new_pwd"
name="new_pwd"
placeholder="<?= lang("App.profile_password_ph") ?>"
value=""
/>
</div>
<div class="mb-3 col-md-6">
<label for="new_pwd_confirm" class="form-label"><?= lang("App.profile_confirm_password") ?></label>
<input
class="form-control"
tabindex="5"
type="text"
id="new_pwd_confirm"
name="new_pwd_confirm"
placeholder="<?= lang("App.profile_confirm_password_ph") ?>"
value=""
/>
</div>
</div>
<div class="mt-2">
<button type="submit" class="btn btn-primary me-2"><?= $btn_submit['title'] ?? '' ?></button>
<button type="reset" class="btn btn-label-secondary"><?= $btn_return['title'] ?? '' ?></button>
<button type="submit" class="btn btn-primary me-2"><?= lang("Basic.global.Save") ?? '' ?></button>
<?= anchor(route_to("home"), lang("Basic.global.Cancel"), ["class" => "btn btn-danger"]) ?>
</div>
</form>
</div>
@ -96,12 +123,7 @@
<?= $this->section('additionalInlineJs') ?>
"use strict";
$(document).ready(function () {
$('#first_name').focus();
$('#first_name').focus();
});
$('.file-upload').on('click', function (e) {
e.preventDefault();
$('#file').trigger('click');
});
<?= $this->endSection() ?>

View File

@ -1,444 +0,0 @@
<!--Style-->
<link href="<?= site_url("themes/focus2/vendor/bootstrap-material-datetimepicker/css/bootstrap-material-datetimepicker.css") ?>"
rel="stylesheet">
<style>
.input_hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
</style>
<!--Content Body-->
<div class="content-body">
<div class="container-fluid">
<div class="row page-titles mx-0">
<div class="col-sm-6 p-md-0">
<div class="welcome-text">
<h4><i class="<?= $title['icon'] ?? '' ?>"></i> <?= $title['module'] ?? '' ?></h4>
<span class="ml-1"><?= $title['page'] ?? '' ?></span>
</div>
</div>
<div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
<ol class="breadcrumb">
<?php foreach ($breadcrumb ?? [] as $item) : ?>
<?php if (!$item['active']) : ?>
<li class="breadcrumb-item"><a
href="<?= site_url($item['route']) ?>"><?= $item['title'] ?></a></li>
<?php else : ?>
<li class="breadcrumb-item active"><?= $item['title'] ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h4 class="card-title"><?= $title['page'] ?? '' ?></h4>
</div>
<div class="card-body">
<?= formAlert() ?>
<form class="form" action="<?= site_url("profile/store") ?>" method="post">
<?= csrf_field() ?>
<div class="form-body">
<div class="row">
<div class="col-lg-12">
<label class="text-primary"><?= lang("App.profile_msg_desc_1") ?></label>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="text-dark"><?= lang("App.profile_first_name") ?></label>
<input type="text" id="first_name" name="first_name" class="form-control"
placeholder="<?= lang("App.profile_first_name_ph") ?>"
value="<?= (isset($obj)) ? $obj->first_name : set_value('first_name'); ?>">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="text-dark"><?= lang("App.profile_last_name") ?></label>
<input type="text" id="last_name" name="last_name" class="form-control"
placeholder="<?= lang("App.profile_last_name_ph") ?>"
value="<?= (isset($obj)) ? $obj->last_name : set_value('last_name'); ?>">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label class="text-dark"><?= lang("App.profile_date_birth") ?></label>
<input type="text" class="form-control"
placeholder="<?= lang("App.profile_date_birth_ph") ?>"
id="date_birth" name="date_birth"
value="<?= (isset($obj)) ? $obj->date_birth : set_value('date_birth'); ?>">
</div>
</div>
<div class="col-lg-8">
<div class="form-group">
<label class="text-dark"><?= lang("App.profile_email") ?></label>
<input type="text" id="email" name="email" class="form-control"
placeholder="<?= lang("App.profile_email_ph") ?>"
value="<?= (isset($obj)) ? $obj->email : set_value('email'); ?>"
disabled>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="mobile"
class="text-dark"><?= lang("App.profile_mobile") ?></label>
<input type="text" id="mobile" name="mobile" class="form-control"
placeholder="<?= lang("App.profile_mobile_ph") ?>"
value="<?= (isset($obj)) ? $obj->mobile : set_value('mobile'); ?>">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="password"
class="text-dark"><?= lang("App.profile_password") ?></label>
<input type="password" id="password" name="password" class="form-control"
placeholder="<?= lang("App.profile_password_ph") ?>">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="confirm_password"
class="text-dark"><?= lang("App.profile_confirm_password") ?></label>
<input type="password" id="confirm_password" name="confirm_password"
class="form-control"
placeholder="<?= lang("App.profile_confirm_password_ph") ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<label class="text-primary"><?= lang("App.profile_msg_desc_2") ?></label>
</div>
<div class="col-lg-8">
<div class="form-group">
<label class="text-dark"><?= lang("App.profile_address") ?></label>
<input type="text" id="address" name="address" class="form-control"
placeholder="<?= lang("App.profile_address_ph") ?>"
value="<?= (isset($obj)) ? $obj->address : set_value('address'); ?>">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="city" class="text-dark"><?= lang("App.profile_city") ?></label>
<input type="text" id="city" name="city" class="form-control"
placeholder="<?= lang("App.profile_city_ph") ?>"
value="<?= (isset($obj)) ? $obj->city : set_value('city'); ?>">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="state"
class="text-dark"><?= lang("App.profile_state") ?></label>
<input type="text" id="state" name="state" class="form-control"
placeholder="<?= lang("App.profile_state_ph") ?>"
value="<?= (isset($obj)) ? $obj->state : set_value('state'); ?>">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="country"
class="text-dark"><?= lang("App.profile_country") ?></label>
<?php $id_select = (isset($obj)) ? $obj->country ?? [] : set_value('country'); ?>
<select name="country" id="country" class="form-control">
<option value=""><?= lang("App.global_select") ?></option>
<?php foreach ($country ?? [] as $item) : ?>
<option value="<?= $item['code'] ?? '' ?>" <?= $id_select == $item['code'] ? 'selected' : '' ?>><?= $item['name'] ?? '' ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="language"
class="text-dark"><?= lang("App.profile_language") ?></label>
<?php $id_select = (isset($obj)) ? $obj->language ?? [] : set_value('language'); ?>
<select name="language" id="language" class="form-control">
<option value=""><?= lang("App.global_select") ?></option>
<option value="en" <?= $id_select == "en" ? 'selected' : '' ?>><?= lang("App.lang_en") ?></option>
<option value="es" <?= $id_select == "es" ? 'selected' : '' ?>><?= lang("App.lang_es") ?></option>
<option value="pt" <?= $id_select == "pt" ? 'selected' : '' ?>><?= lang("App.lang_pt") ?></option>
</select>
</div>
</div>
</div>
</div>
<div class="form-actions">
<a href="<?= site_url($btn_return['route'] ?? '#') ?>"
class="<?= $btn_return['class'] ?? '' ?>">
<i class="<?= $btn_return['icon'] ?? '' ?>"></i> <?= $btn_return['title'] ?? '' ?>
</a>
<button type="submit" class="<?= $btn_submit['class'] ?? '' ?>">
<i class="<?= $btn_submit['icon'] ?? '' ?>"></i> <?= $btn_submit['title'] ?? '' ?>
</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h4 class="card-title"><?= lang("App.profile_subtitle_image") ?></h4>
</div>
<div class="card-body">
<div class="row">
<div class="col-lg-12 justify-content-center d-flex">
<img src="<?= $obj->picture ?? '' ?>" class="btn-circle btn-circle-md">
</div>
<div class="col-lg-12 text-center mt-3">
<span><b><?= $obj->first_name ?? '' ?></b></span><br>
<span><?= $obj->email ?? '' ?></span>
</div>
<div class="col-lg-12 mt-3">
<button type="button" class="btn btn-primary btn-block" data-toggle="modal"
data-target="#photoModalCenter"><i
class="fas fa-camera"></i> <?= lang("App.profile_change_photo") ?></button>
</div>
<!-- Modal -->
<div class="modal fade" id="photoModalCenter">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-lg-12 mb-2">
<h5><?= lang("App.profile_change_image") ?></h5>
</div>
<div class="col-lg-3 mt-2">
<div class="row">
<div class="col-lg-12 justify-content-center d-flex">
<form name="form_upload" class="form"
action="<?= site_url("profile") ?>"
enctype="multipart/form-data" method="post">
<?= csrf_field() ?>
<input type="file" name="file" id="file"
class="input_hidden"
onchange="form_upload.submit()" accept="image/*">
<div class="btn btn-light btn-circle btn-circle-md"><a
href="#" class="file-upload"><i
class="fas fa-cloud-upload-alt fa-2xl"></i></a>
</div>
</form>
</div>
<div class="col-lg-12 text-center mt-1">
<b><i class="fas fa-upload"></i> <?= strtoupper(lang("App.profile_upload_msg")) ?>
</b>
</div>
</div>
</div>
<div class="col-lg-3 mt-2">
<div class="row">
<div class="col-lg-12 justify-content-center d-flex">
<form name="form_not" action="<?= site_url("profile") ?>"
method="post">
<?= csrf_field() ?>
<input type="hidden" id="image_not" name="image_not"
value="<?= site_url("assets/img/default-user.png") ?>">
<a href="javascript:form_not.submit()"><img
src="<?= site_url("assets/img/default-user.png") ?>"
class="btn-circle btn-circle-md"></a>
</form>
</div>
<div class="col-lg-12 text-center mt-1">
<b><i class="fas fa-user-slash"></i> <?= strtoupper(lang("App.profile_no_image_msg")) ?>
</b>
</div>
</div>
</div>
<div class="col-lg-3 mt-2">
<div class="row">
<div class="col-lg-12 justify-content-center d-flex">
<form name="form_gravatar"
action="<?= site_url("profile") ?>" method="post">
<?= csrf_field() ?>
<input type="hidden" id="image_gravatar"
name="image_gravatar"
value="https://s.gravatar.com/avatar/<?= MD5($obj->email ?? '') ?>?s=150">
<a href="javascript:form_gravatar.submit()"><img
src="https://s.gravatar.com/avatar/<?= MD5($obj->email ?? '') ?>?s=150"
class="btn-circle btn-circle-md"></a>
</form>
</div>
<div class="col-lg-12 text-center mt-1">
<b><i class="fas fa-user-circle"></i> <?= strtoupper(lang("App.profile_gravatar_msg")) ?>
</b>
</div>
</div>
</div>
<?php foreach ($oauth ?? [] as $item) : ?>
<?php
$icon = '';
switch ($item['provider']) {
case "vkontakte":
$icon = '<i class="fab fa-vk"></i> ';
break;
case "wechat":
$icon = '<i class="fab fa-weixin"></i> ';
break;
default:
$icon = '<i class="fab fa-' . $item['provider'] . '"></i> ';
break;
}
?>
<div class="col-lg-3 mt-2">
<div class="row">
<div class="col-lg-12 justify-content-center d-flex">
<form name="form_<?= $item['provider'] ?? '' ?>"
action="<?= site_url("profile") ?>" method="post">
<?= csrf_field() ?>
<input type="hidden"
id="image_<?= $item['provider'] ?? '' ?>"
name="image_<?= $item['provider'] ?? '' ?>"
value="<?= $item['picture'] ?? '' ?>">
<a href="javascript:form_<?= $item['provider'] ?? '' ?>.submit()"><img
src="<?= $item['picture'] ?? '' ?>"
class="btn-circle btn-circle-md"></a>
</form>
</div>
<div class="col-lg-12 text-center mt-1">
<b><?= $icon ?><?= strtoupper($item['provider'] ?? '') ?></b>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $settings = session()->get('settings'); ?>
<?php if ($settings['two_factor_auth']) : ?>
<form name="form_otp" class="form" action="<?= site_url("profile/store") ?>" method="post" id="sendFormTFA">
<?= csrf_field() ?>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<div class="row mx-0" style="width: 100%;">
<div class="col-sm-6 p-md-0">
<h4 class="card-title"><?= lang("App.profile_subtitle_tfa") ?></h4>
</div>
<div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
<div class="custom-control custom-switch ml-2">
<input type="checkbox" id="tfa" name="tfa" class="custom-control-input"
onchange="tfaView()" <?= $obj['tfa'] ?? false ? 'checked' : '' ?>>
<label for="tfa"
class="custom-control-label"><?= lang("App.profile_tfa_msg") ?></label>
</div>
</div>
</div>
</div>
<div class="card-body">
<div id="otp" style="display: <?= $obj['tfa'] ?? false ? 'block' : 'none' ?>">
<?php
$tfa = new \App\Libraries\Authenticator();
$name = $obj['first_name'] ?? '';
if ($obj['tfa'] && !empty($obj['tfa_secret'])) {
$tfa_secret = $obj['tfa_secret'] ?? '';
$qrcode = $tfa->GetQR("{$settings['title']} ({$name})", $tfa_secret);
} else {
$tfa_secret = $tfa->createSecret();
$qrcode = $tfa->GetQR("{$settings['title']} ({$name})", $tfa_secret);
}
?>
<div class="row">
<div class="col-lg-6">
<p><b><?= lang("App.profile_qrcode") ?></b></p>
<img src="<?php echo $qrcode; ?>" class="img-responsive">
</div>
<div class="col-lg-6">
<p><b><?= lang("App.profile_backup_code") ?></b></p>
<?php
$codes = "";
if (!empty($obj['tfa_code'] ?? '')) {
$codes = explode(',', $obj['tfa_code'] ?? '');
foreach ($codes as $item) {
echo '<span class="badge badge-primary mr-2 mb-1">' . $item . '</span>';
}
} else {
$codes = array();
for ($i = 1; $i <= 8; $i++) {
$code = random_string('numeric', 6);
$codes[] = $code;
echo '<span class="badge badge-primary mr-2 mb-1">' . $code . '</span>';
}
}
?>
<p class="mt-2"><b><?= lang("App.profile_tfa_secret") ?></b><br><b
class="text-primary"><?= $tfa_secret ?></b></p>
<input type="hidden" id="tfa_secret" name="tfa_secret"
value="<?= $tfa_secret ?>">
<input type="hidden" id="tfa_code" name="tfa_code"
value="<?= implode(',', $codes) ?>">
<button type="button" class="btn btn-primary btn-block mt-2"
onclick="download('<?= lang("App.profile_qrcode") ?>\n<?= implode(",", $codes) ?>\n<?= lang("App.profile_tfa_secret") ?>\n<?= $tfa_secret ?>','backup_codes.txt')">
<i class="fas fa-download mr-1"></i> <?= lang("App.profile_tfa_download") ?>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<?php endif; ?>
</div>
</div>
<!-- Required vendors -->
<script src="<?= site_url("themes/focus2/vendor/global/global.min.js") ?>">></script>
<script src="<?= site_url("themes/focus2/js/quixnav-init.js") ?>">></script>
<script src="<?= site_url("themes/focus2/js/custom.min.js") ?>">></script>
<script src="<?= site_url("themes/focus2/vendor/select2/js/select2.full.min.js") ?>">></script>
<!-- Alert -->
<script src="<?= site_url("themes/focus2/vendor/sweetalert2/dist/sweetalert2.min.js") ?>">></script>
<script src="<?= site_url("themes/focus2/vendor/toastr/js/toastr.min.js") ?>">></script>
<!-- Date Range Picker -->
<!-- momment js is must -->
<script src="<?= site_url("themes/focus2/vendor/moment/moment.min.js") ?>">></script>
<script src="<?= site_url("themes/focus2/vendor/bootstrap-daterangepicker/daterangepicker.js") ?>">></script>
<!-- Material color picker -->
<script src="<?= site_url("themes/focus2/vendor/bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker.js") ?>">></script>
<!-- Form -->
<script>
"use strict";
$(document).ready(function () {
$('#first_name').focus();
$("#country").select2();
$("#language").select2();
$('#date_birth').bootstrapMaterialDatePicker({
format: '<?=momentDateJS()?>',
time: false
});
});
$('.file-upload').on('click', function (e) {
e.preventDefault();
$('#file').trigger('click');
});
function download(text, filename) {
let blob = new Blob([text], {type: "text/plain;charset=utf-8"});
let url = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
}
function tfaView() {
document.getElementById("sendFormTFA").submit();
}
</script>
<?= sweetAlert() ?>