mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Intentnado resolver conflicto
This commit is contained in:
4
.idea/safekat.iml
generated
4
.idea/safekat.iml
generated
@ -1,9 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="WEB_MODULE" version="4">
|
<module type="WEB_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/ci4/app/ThirdParty/DatatablesEditor/" isTestSource="false" packagePrefix="DataTables\" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
205
ci4/app/Filters/LoginAuthFilter.php
Normal file
205
ci4/app/Filters/LoginAuthFilter.php
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use App\Models\SettingsModel;
|
||||||
|
use CodeIgniter\Filters\FilterInterface;
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class LoginAuthFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
public function before(RequestInterface $request, $arguments = null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if(!$this->validateIgnoreControllerAccess()){
|
||||||
|
$session = session();
|
||||||
|
$token = $session->get('token')??'';
|
||||||
|
$tfa = $session->get('tfa')??false;
|
||||||
|
|
||||||
|
$this->getSettings();
|
||||||
|
|
||||||
|
if (empty($token) || $tfa == true) {
|
||||||
|
return redirect()->to('/login');
|
||||||
|
}else{
|
||||||
|
$this->validateControllerAccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access to controllers is valid.
|
||||||
|
*/
|
||||||
|
public function validateControllerAccess(){
|
||||||
|
$request = \Config\Services::request();
|
||||||
|
$uri = $request->uri;
|
||||||
|
|
||||||
|
$language = \Config\Services::language();
|
||||||
|
$language->setLocale(session()->lang);
|
||||||
|
|
||||||
|
$getWhiteList = $this->whiteListController();
|
||||||
|
|
||||||
|
foreach ($getWhiteList as $item){
|
||||||
|
if(strtolower($item) == $uri->getSegment(1)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$getRules = json_decode(session()->get('rules')??'[]');
|
||||||
|
|
||||||
|
foreach ($this->whiteListMethod() as $item){
|
||||||
|
if(strtolower($item) == $uri->getSegment(2)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($getRules as $key=>$value){
|
||||||
|
if(strtolower($key) == $uri->getSegment(1)){
|
||||||
|
if($uri->getTotalSegments() <= 1){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
foreach ($value as $item){
|
||||||
|
if(strtolower($item) == $uri->getSegment(2)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
foreach($this->controllerFolderWhiteList() as $folder){
|
||||||
|
if(strtolower($folder) == $uri->getSegment(1)){
|
||||||
|
if(strtolower($key) == $uri->getSegment(2)){
|
||||||
|
if($uri->getTotalSegments() <= 2){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($value as $item){
|
||||||
|
if(strtolower($item) == $uri->getSegment(3)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session()->setFlashdata('sweet', ['error',lang("App.dashboard_alert_rules")]);
|
||||||
|
header('Location: /home');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JJO
|
||||||
|
* Returns the controller folder list
|
||||||
|
*/
|
||||||
|
public function controllerFolderWhiteList(){
|
||||||
|
return [
|
||||||
|
'Catalogo',
|
||||||
|
'Clientes',
|
||||||
|
'Compras',
|
||||||
|
'Configuracion',
|
||||||
|
'EnviosLogistica',
|
||||||
|
'Facturacion',
|
||||||
|
'Informes',
|
||||||
|
'Importacion',
|
||||||
|
'Pedidos',
|
||||||
|
'Presupuestos',
|
||||||
|
'Produccion',
|
||||||
|
'Proveedores',
|
||||||
|
'Servicios',
|
||||||
|
'Tarifas',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the white list of allowed controllers.
|
||||||
|
*/
|
||||||
|
public function whiteListController(){
|
||||||
|
return [
|
||||||
|
'Js_loader',
|
||||||
|
'BaseController',
|
||||||
|
'Home',
|
||||||
|
'Login',
|
||||||
|
'Oauth',
|
||||||
|
'Language',
|
||||||
|
'Api',
|
||||||
|
'Cron',
|
||||||
|
'lang',
|
||||||
|
'Ajax',
|
||||||
|
'Integration',
|
||||||
|
'Migrate',
|
||||||
|
'Test',
|
||||||
|
'Viewmode',
|
||||||
|
'GoBaseController',
|
||||||
|
'GoBaseResourceController',
|
||||||
|
'Maquinaspapelesimpresion',
|
||||||
|
'Maquinastarifasimpresion',
|
||||||
|
'Maquinascalles',
|
||||||
|
'My', 'Usuarios', 'Notification' // PARA LA DEMO
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the whitelist of public controllers.
|
||||||
|
*/
|
||||||
|
public function ignoreListController(){
|
||||||
|
return [
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateIgnoreControllerAccess(){
|
||||||
|
$request = \Config\Services::request();
|
||||||
|
$uri = $request->uri;
|
||||||
|
|
||||||
|
$getList = $this->ignoreListController();
|
||||||
|
foreach ($getList as $item){
|
||||||
|
if(strtolower($item) == $uri->getSegment(1)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function whiteListMethod(){
|
||||||
|
return [
|
||||||
|
'initController',
|
||||||
|
'__construct',
|
||||||
|
'validateControllerAccess',
|
||||||
|
'whiteListController',
|
||||||
|
'whiteListMethod',
|
||||||
|
'allItemsSelect',
|
||||||
|
'menuItems',
|
||||||
|
'datatable',
|
||||||
|
'datatable_editor',
|
||||||
|
'datatable_2',
|
||||||
|
'datatable_editor_2',
|
||||||
|
'collect',
|
||||||
|
'cast',
|
||||||
|
'getGramaje',
|
||||||
|
'presupuesto',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSettings(){
|
||||||
|
// Get Settings
|
||||||
|
$session = session();
|
||||||
|
$settingsBase = new SettingsModel();
|
||||||
|
$settings = $settingsBase->first()??[];
|
||||||
|
$session->set('settings', $settings);
|
||||||
|
if(empty($session->get('lang'))) {
|
||||||
|
$session->set('lang', $settings['default_language'] ?? 'es');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user