Browse Source

Implementaciones del login, administrador de sistes y usuarios y perfiles

Jose Brito 3 years ago
parent
commit
c30f88979b

+ 13 - 1
sistema-mantenimiento-back/app/Exceptions/Handler.php

@@ -4,6 +4,7 @@ namespace App\Exceptions;
 
 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
 use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Illuminate\Database\QueryException;
 use Throwable;
 
@@ -50,10 +51,21 @@ class Handler extends ExceptionHandler
             return response($respuesta, 405)->header('Content-Type', 'application/json');
         });
 
+        $this->renderable(function (NotFoundHttpException $e, $request){
+            $respuesta = json_encode([
+                "error" => true,
+                "msg" => "ERR_GLB_USU001: La ruta solicitada no existe: " . $request->fullUrl(),
+                "response" => []
+            ]);
+    
+            return response($respuesta, 404)->header('Content-Type', 'application/json');
+        });
+
         $this->renderable(function (QueryException $e, $request){
             $respuesta = json_encode([
                 "error" => true,
-                "msg" => "ERR_GLB_USU000: No se pudo establecer una conexión con la base de datos: " . $e->getMessage(),
+                //"msg" => "ERR_GLB_USU002: No se pudo establecer una conexión con la base de datos. Código de error: " . $e->getCode(),
+                "msg" => "ERR_GLB_USU002: No se pudo establecer una conexión con la base de datos. Código de error: " . $e->getMessage(),
                 "response" => []
             ]);
     

+ 106 - 0
sistema-mantenimiento-back/app/Http/Controllers/FunctionsController.php

@@ -0,0 +1,106 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Carbon;
+
+class FunctionsController extends Controller{
+    public function __construct(){}
+
+    public static function uuidv5($namespace, $name) {
+        if(!self::is_valid($namespace)) return false;
+
+        // Get hexadecimal components of namespace
+        $nhex = str_replace(array('-','{','}'), '', $namespace);
+
+        // Binary Value
+        $nstr = '';
+
+        // Convert Namespace UUID to bits
+        for($i = 0; $i < strlen($nhex); $i+=2) {
+            $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
+        }
+
+        // Calculate hash value
+        $hash = sha1($nstr . $name);
+
+        return sprintf('%08s-%04s-%04x-%04x-%12s',
+
+            // 32 bits for "time_low"
+            substr($hash, 0, 8),
+
+            // 16 bits for "time_mid"
+            substr($hash, 8, 4),
+
+            // 16 bits for "time_hi_and_version",
+            // four most significant bits holds version number 5
+            (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
+
+            // 16 bits, 8 bits for "clk_seq_hi_res",
+            // 8 bits for "clk_seq_low",
+            // two most significant bits holds zero and one for variant DCE1.1
+            (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
+
+            // 48 bits for "node"
+            substr($hash, 20, 12)
+        );
+    }
+
+    public static function is_valid($uuid) {
+        return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
+                        '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
+    }
+
+    public function generateID(){
+        
+    }
+
+    public function getType($type){
+        switch($type){
+            case "insert":
+                return "CREATE";
+            break;
+            case "update":
+                return strtoupper($type);
+            break;
+            case "select":
+                return "READ";
+            break;
+            case "delete":
+                return strtoupper($type);
+            break;
+            default:
+                return "UNKNOWN";
+            break;
+        }
+    }
+
+    public function registerActivity($actions, $user, $date, $line){
+        $cont = 1;
+        foreach($actions as $action){
+            $typeStr = explode(" ", $action['query'])[0];
+            $type =  $this->getType($typeStr);
+            $params = json_encode($action['bindings']);
+            $code = $this->uuidv5('1546058f-5a25-4334-85ae-e68f2a44bbaf', $user . $date . $cont);
+            $cont++;
+
+            $id = DB::table('S002V01TACCI')->insertGetId([
+                'ACCI_NULI' => $line,
+                'ACCI_COAC' => $code,
+                'ACCI_TIAC' => $type,
+                'ACCI_QUER' => $action['query'],
+                'ACCI_PARA' => $params,
+                'ACCI_FEAC' => $date,
+                'ACCI_IDUS' => $user,
+            ]);
+
+            DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $user)->update([
+                'USUA_ULAC' => $id
+            ]);
+        }
+    }
+}

+ 118 - 12
sistema-mantenimiento-back/app/Http/Controllers/LoginController.php

@@ -11,23 +11,30 @@ use Illuminate\Support\Carbon;
 use Firebase\JWT\JWT;
 use Firebase\JWT\Key;
 
+use Exception;
+
 class LoginController extends Controller{
     private $responseController;
     private $encryptionController;
+    private $functionsController;
     private $secretKey = "ydl27x22cNsNY0z6o3Fr6XZoUvsX0QMZx6MaiwN+KCnM6APS4Xbb7GDfudOYD5uD/r8TzQElh4d4HIal5Os0XA==";
+    private $publicKey = "zOgD0uF22+xg37nTmA+bg/6/E80BJYeHeByGpeTrNFw=";
 
     public function __construct(){
         $this->responseController = new ResponseController();
         $this->encryptionController = new EncryptionController();
+        $this->functionsController = new FunctionsController;
     }
 
     public function login(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
             'email' => 'required|string|email',
-            'password' => 'required|string'
+            'password' => 'required|string',
+            'linea' => 'required|integer|max: 2',
+            'lugarConexion' => "required|json"
         ]);
 
-
         if($validator->fails()){
             return $this->responseController->makeResponse(
                 true,
@@ -40,28 +47,62 @@ class LoginController extends Controller{
         }
 
         $login = $request->all();
-        $usr = DB::table('users')->where('email', '=', $login['email'])->first();
+        $usr = DB::table('S002V01TUSUA')->where('USUA_COEL', '=', $login['email'])->first();
 
         if(is_null($usr)){
             return $this->responseController->makeResponse(true, "El correo electrónico no está registrado.", [], 404);
+        }else if($usr->USUA_ESTA != 'Activo'){
+            $statusStr = strtolower($usr->USUA_ESTA);
+            return $this->responseController->makeResponse(true, "El usuario se encuentra $statusStr, por favor contacte al administrador para solucionarlo.", [], 401);
         }
+        
+        $now = Carbon::now('America/Mexico_city');
+        $nowStr = $now->toDateTimeString();
 
-        $contra = $usr->password;
-        if(!Hash::check($login['password'], $contra)){
-            return $this->responseController->makeResponse(true, "La contraseña es incorrecta.", [], 401);
+        $contra = $login['password'];
+        $contra = $this->encryptionController->decrypt($contra);
+        if(!$contra){
+            return $this->responseController->makeResponse(true, 'La contraseña no fue encriptada correctamente.', [], 400);
         }
+        $usrContra = $usr->USUA_CONT;
+        if(!Hash::check($contra, $usrContra)){
+            $attempts = $usr->USUA_ININ + 1;
+            $status = $attempts >= 10 ? 'Inactivo' : 'Activo';
+
+            DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $usr->USUA_IDUS)->update([
+                "USUA_ININ" => $attempts,
+                "USUA_ESTA" => $status
+            ]);
+
+            return $this->responseController->makeResponse(true, "La contraseña es incorrecta, intento $attempts de 10.", [], 401);
+        }
+
+        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $usr->USUA_IDUS)->update([
+            "USUA_ININ" => 0,
+            "USUA_ESTA" => 'Activo'
+        ]);
 
-        $now = Carbon::now('America/Mexico_city');
-        $nowStr = $now->toDateTimeString();
         $iat = $now->timestamp;
         $cad = $now->addDay()->timestamp;
+        $ipv = $request->ip();
         
         try{
-            DB::table('users')->where('email', '=', $login['email'])->update(['lastConnection' => $nowStr]);
+            $ulco = DB::table('S002V01TBIAC')->insertGetId([
+                'BIAC_NULI' => $login['linea'],
+                'BIAC_IDUS' => $usr->USUA_IDUS,
+                'BIAC_DIIP' => $ipv,
+                'BIAC_LUCO' => $login['lugarConexion'],
+                'BIAC_FECO' => $nowStr
+            ]);
+            DB::table('S002V01TUSUA')->where('USUA_COEL', '=', $login['email'])->update(['USUA_ULCO' => $ulco]);
         }catch(PDOException $e){
             return $this->responseController->makeResponse(true, "Hubo un error al intentar actualizar la última conexión.", [], 500);
         }
 
+        //Antes de crear el token revisamos los permisos de su perfil
+        $profile = DB::table('S002V01TPERF')->where('PERF_IDPE', '=', $usr->USUA_PERF)->get()->first();
+        $permissions = $this->encryptionController->encrypt($profile->PERF_PERM);
+
         $payload = [
             "iss" => $login['email'],
             "aud" => "dominio.syp.mx",
@@ -71,11 +112,76 @@ class LoginController extends Controller{
 
         $token = JWT::encode($payload, $this->secretKey, 'EdDSA');
 
+        //Antes de realizar el return obtenemos todas las acciones realizadas en la base de datos
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $usr->USUA_IDUS, $nowStr, $login['linea']);
+
         return $this->responseController->makeResponse(false, "EXITO.", [
-            "IDUSUARIO" => $this->encryptionController->encrypt($usr->id),
-            "NOMBREUSUARIO" => $this->encryptionController->encrypt($usr->name),
-            "CORREO" => $this->encryptionController->encrypt($usr->email),
+            "IDUSUARIO" => $this->encryptionController->encrypt($usr->USUA_IDUS),
+            "NOMBREUSUARIO" => $this->encryptionController->encrypt($usr->USUA_NOMB),
+            "CORREO" => $this->encryptionController->encrypt($usr->USUA_COEL),
+            "PERMISOS" => $permissions,
             "TOKEN" => $token,
         ]);
     }
+
+    public function verifyToken(Request $request){
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'token' => 'required|string',
+        ]);
+
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $tokenInfo = $request->all();
+        try{
+            $decoded = JWT::decode($tokenInfo['token'], new Key($this->publicKey, 'EdDSA'));
+        }catch(Exception $e){
+            return $this->responseController->makeResponse(false, "Token inválido", [
+                "validToken" => false
+            ]);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where('USUA_COEL', '=', $decoded->iss)->first();
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(false, "El usuario que generó el token no está registrado en la base.", [
+                "validToken" => false
+            ]);
+        }
+
+        if($decoded->aud != "dominio.syp.mx"){
+            return $this->responseController->makeResponse(false, "El token enviado fue generado en un sitio diferente.", [
+                "validToken" => false
+            ]);
+        }
+
+        $now = Carbon::now('America/Mexico_city')->timestamp;
+        if($now > $decoded->cad){
+            return $this->responseController->makeResponse(false, "Token expirado.", [
+                "validToken" => false
+            ]);
+        }
+
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $usr->USUA_IDUS, $nowStr, 1);
+        return $this->responseController->makeResponse(false, "Token válido.", [
+            "validToken" => true
+        ]);
+    }
+
+    public function createPasword(Request $request){
+        $pass = $request->only('pass');
+        $uuid = $this->functionsController->uuidv5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'jose.b@ittec.mx');
+        return $this->responseController->makeResponse(false, $uuid, []);
+    }
 }

+ 198 - 14
sistema-mantenimiento-back/app/Http/Controllers/SystemAdministratorController.php

@@ -11,28 +11,40 @@ use Illuminate\Support\Carbon;
 class SystemAdministratorController extends Controller{
     private $responseController;
     private $encryptionController;
+    private $functionsController;
 
     public function __construct(){
         $this->responseController = new ResponseController();
         $this->encryptionController = new EncryptionController();
+        $this->functionsController = new FunctionsController();
     }
 
-    public function getLastConnections(){
-        try{
-            $lastConnections = DB::table('users')->select(
-                'id as IDUSUARIO',
-                'lastConnection as ULCON'
-            )->get();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+    public function getLastConnections($idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
         }
 
+        $lastConnections = DB::table('S002V01TUSUA')->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')->select(
+            'USUA_IDUS AS IDUSUARIO',
+            'BIAC_FECO AS ULCON'
+        )->get()->all();
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
         return $this->responseController->makeresponse(false, "EXITO", $lastConnections);
     }
 
     public function setLastConnection(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
             'id' => 'required|string',
+            'linea' => 'required|integer',
+            'lugarConexion' => 'required|json'
         ]);
 
         if($validator->fails()){
@@ -50,18 +62,190 @@ class SystemAdministratorController extends Controller{
 
         $idUser = $this->encryptionController->decrypt($user['id']);
         if(!$idUser){
-            return $this->responseController->makeResponse(true, "La cadena enviada no pudo ser desencriptada.", [], 400);
+            return $this->responseController->makeResponse(true, "La ID del usuario no está encriptado correctamente.", [], 400);
         }
 
         $now = Carbon::now('America/Mexico_city');
         $nowStr = $now->toDateTimeString();
+        $ipv = $request->ip();
 
-        try{
-            DB::table('users')->where('id', '=', $idUser)->update(['lastConnection' => $nowStr]);
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "Hubo un error al intentar actualizar la última conexión.", [], 500);
-        }
+        
+        $idLastConn = DB::table('S002V01TBIAC')->insertGetId([
+            'BIAC_NULI' => $user['linea'],
+            'BIAC_IDUS' => $user['linea'],
+            'BIAC_DIIP' => $ipv,
+            'BIAC_LUCO' => $user['lugarConexion'],
+            'BIAC_FECO' => $nowStr
+        ]);
+
+        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update(['USUA_ULCO' => $idLastConn]);
 
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $user['linea']);
         return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
     }
+
+    public function getCatalogues($idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $catalogues = DB::table('S002V01TCATA')->select(
+            'CATA_IDCA AS IDCATALOGO',
+            'CATA_NOCA AS NOMBRECATALOGO',
+            'CATA_VERS AS VERSION'
+        )->get()->all();
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeresponse(false, "EXITO", $catalogues);
+    }
+
+    //Pendiente
+    public function registerCatalogue(Request $request){
+        if(!$request->hasFile('xls')){
+            return $this->responseController->makeResponse(true, "No se envió ningún archivo.", [], 400);
+        }
+
+        $validator = Validator::make($request->all(), [
+            'type' => 'required|string',
+        ]);
+
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $allowedFiles = ["Colonias", "Códigos postales", "Estados", "Localidades", "Municipios"];
+        if(!in_array($form['type'], $allowedFiles)){
+            return $this->responseController->makeResponse(true, "El tipo de catálogo no está soportado.", [], 400);
+        }
+
+        $file = $request->file('xls');
+        $ext = $request->file('xls')->getClientOriginalName();
+        $extArr = explode(".", $ext);
+        $extStr = end($extArr);
+
+        if(!($extStr == "xls" || $extStr == "xlsx")){
+            return $this->responseController->makeResponse(true, "La extensión del archivo no está soportada.", [], 400);
+        }
+
+        require '../../../spreadsheet/vendor/autoload.php';
+        var_dump($extStr);
+    }
+
+    public function getUserConnections($id, $idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $id = $this->encryptionController->decrypt($id);
+        if(!$id){
+            return $this->responseController->makeResponse(true, "El id del usuario que desea consultar no está encriptado correctamente.", [], 400);
+        }
+
+        $userInfo = DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $id)->get()->first();
+        if(is_null($userInfo)){
+            return $this->responseController->makeResponse(true, "El usuario que desea consultaro no existe.", [], 404);
+        }
+
+        $connections = DB::table('S002V01TBIAC')->select(
+            'BIAC_DIIP AS IP',
+            'BIAC_LUCO AS LUGAR',
+            'BIAC_FECO AS FECHA'
+        )->where('BIAC_IDUS', '=', $id)->orderBy('BIAC_FECO', 'desc')->get()->all();
+
+        $responseArr = [
+            'NOMBRE' => $userInfo->USUA_NOMB,
+            'APPAT' => $userInfo->USUA_APPA,
+            'APMAT' => $userInfo->USUA_APMA,
+            'ULTCON' => $userInfo->USUA_ULCO,
+            'HISTORIAL' => $connections
+        ];
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeResponse(false, "EXITO", $responseArr);
+    }
+
+    public function getLastActions($idUser, $line){
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El ID el usuario que realizó la petición no está encriptado correctamente.", [], 400);
+        }
+
+        $tiposAcciones = ['READ' => 'Lectura de datos', 'UPDATE' => 'Actualización de datos', 'CREATE' => 'Registro de información', 'DELETE' => 'Eliminación de datos'];
+        $lastActions = DB::table('S002V01TUSUA')->leftJoin('S002V01TACCI', 'USUA_ULAC', '=', 'ACCI_IDAC')->select(
+            'USUA_IDUS AS IDUSUARIO',
+            'ACCI_TIAC AS TIPOACCION',
+            'ACCI_FEAC AS FECHA'
+        )->get()->all();
+
+        foreach($lastActions as $action){
+            if(is_null($action->TIPOACCION)){
+                $action->TIPOACCION = '-';
+            }else{
+                $action->TIPOACCION = $tiposAcciones[$action->TIPOACCION];
+            }
+        }
+
+        return $this->responseController->makeResponse(false, 'EXITO', $lastActions);
+    }
+
+    public function getUserActions($id, $idUser, $line){
+        $id = $this->encryptionController->decrypt($id);
+        if(!$id){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que desea consultar no está encriptado correctamente.', [], 400);
+        }
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
+        }
+
+        $userInfo = DB::table('S002V01TUSUA')->select(
+            'USUA_IDUS AS IDUSUARIO',
+            'USUA_NOMB AS NOMBRE',
+            'USUA_APPA AS APEPAT',
+            'USUA_APMA AS APEMAT'
+        )->where('USUA_IDUS', '=', $id)->get()->first();
+
+        if(is_null($userInfo)){
+            return $this->responseController->makeResponse(true, 'El usuario solicitado no existe.', [], 404);
+        }
+
+        $actions = DB::table('S002V01TACCI')->select(
+            'ACCI_COAC AS CODIGO',
+            'ACCI_TIAC AS TIPOACCION',
+            'ACCI_QUER AS SCRIPT',
+            'ACCI_PARA AS PARAMETROS',
+            'ACCI_FEAC AS FECHA'
+        )->where('ACCI_IDUS', '=', $id)->get()->all();
+
+        $actionTypes = ['READ' => 'Lectura de datos', 'UPDATE' => 'Actualización de datos', 'CREATE' => 'Registro de información', 'DELETE' => 'Eliminación de datos'];
+        foreach($actions as $action){
+            $action->TIPOACCION = $actionTypes[$action->TIPOACCION];
+        }
+
+        $userInfo->HISTORIAL = $actions;
+        
+        return $this->responseController->makeResponse(false, 'EXITO', $userInfo);
+    }
 }

+ 577 - 126
sistema-mantenimiento-back/app/Http/Controllers/UsersProfilesController.php

@@ -6,96 +6,209 @@ use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Carbon;
 
 class UsersProfilesController extends Controller{
     private $responseController;
+    private $encryptionController;
+    private $functionsController;
 
     public function __construct(){
         $this->responseController = new ResponseController();
+        $this->encryptionController = new EncryptionController();
+        $this->functionsController = new FunctionsController();
     }
     
-    public function getUsers(){
-        try{
-            $users = DB::table('users')->join('profiles', 'users.profile', '=', 'profiles.id')->select(
-                'users.id as IDUSUARIO',
-                'users.name as NOMBRE',
-                'users.fLastName as APEPAT',
-                'users.sLastName as APEMAT',
-                'users.email as EMAIL',
-                'profiles.name as PERFIL',
-                'users.status as ESTATUS',
-                'users.lastConnection as ULCON'
-            )->get();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+    public function getUsers($idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
         }
         
+        $users = DB::table('S002V01TUSUA')
+        ->join('S002V01TPERF', 'USUA_PERF', '=', 'PERF_IDPE')
+        ->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')
+        ->select(
+            'USUA_IDUS as IDUSUARIO',
+            'USUA_NOMB as NOMBRE',
+            'USUA_APPA as APEPAT',
+            'USUA_APMA as APEMAT',
+            'USUA_COEL as EMAIL',
+            'PERF_NOPE as PERFIL',
+            'USUA_ESTA as ESTATUS',
+            'BIAC_FECO as ULCON'
+        )->get()->all();
+        
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
         return $this->responseController->makeresponse(false, "EXITO", $users);
     }
 
-    public function getUser($id){
-        try{
-            $user = DB::table('users')->select(
-                'users.id as IDUSUARIO',
-                'users.name as NOMBRE',
-                'users.fLastName as APEPAT',
-                'users.sLastName as APEMAT',
-                'users.email as EMAIL',
-                'users.profile as PERFIL',
-                'users.status as ESTATUS',
-            )->where('users.id', '=', $id)->get()->first();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+    public function getUser($id, $idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $id = $this->encryptionController->decrypt($id);
+        if(!$id){
+            return $this->responseController->makeResponse(true, "El id del usuario no está encriptado correctamente.", [], 400);
         }
 
+        $user = DB::table('S002V01TUSUA')->select(
+            'USUA_IDUS AS IDUSUARIO',
+            'USUA_NOMB AS NOMBRE',
+            'USUA_APPA AS APEPAT',
+            'USUA_APMA AS APEMAT',
+            'USUA_COEL AS EMAIL',
+            'USUA_PERF AS PERFIL',
+            'USUA_ESTA AS ESTATUS',
+        )->where('USUA_IDUS', '=', $id)->get()->first();
+
         if(is_null($user)){
             return $this->responseController->makeResponse(true, "El usuario consultado no existe.", [], 404);
         }
-        
+
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
         return $this->responseController->makeresponse(false, "EXITO", $user);
     }
 
-    public function getProfiles(){
-        try{
-            $profiles = DB::table('profiles')->select(
-                'id as IDPERFIL',
-                'name as NOMBREPERFIL',
-                'status as ESTATUS',
-                'permissions as PERMISOS'
-            )->get();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+    public function getProfiles($idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
         }
         
+        $profiles = DB::table('S002V01TPERF')->select(
+            'PERF_IDPE as IDPERFIL',
+            'PERF_NOPE as NOMBREPERFIL',
+            'PERF_ESTA as ESTATUS',
+            'PERF_PERM as PERMISOS'
+        )->get();
+
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
+        
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
         return $this->responseController->makeresponse(false, "EXITO", $profiles);
     }
 
-    public function getProfile($id){
-        try{
-            $profile = DB::table('profiles')->select(
-                'id as IDPERFIL',
-                'name as NOMBREPERFIL',
-                'status as ESTATUS',
-                'permissions as PERMISOS'
-            )->where('id', '=', $id)->get()->first();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+    public function getProfile($id, $idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $id = $this->encryptionController->decrypt($id);
+        if(!$id){
+            return $this->responseController->makeResponse(true, "El ID del perfil no está encriptado correctamente.", [], 401);
         }
 
+        $profile = DB::table('S002V01TPERF')->select(
+            'PERF_IDPE AS IDPERFIL',
+            'PERF_NOPE AS NOMBREPERFIL',
+            'PERF_ESTA AS ESTATUS',
+            'PERF_PERM AS PERMISOS',
+        )->where('PERF_IDPE', '=', $id)->first();
+
         if(is_null($profile)){
             return $this->responseController->makeResponse(true, "El perfil consultado no existe.", [], 404);
         }
+
+        $profileInfo = json_decode($profile->PERMISOS, true);
+        $permissions = [];
+        //Se obtienen todos los modulos
+        $modules = DB::table('S002V01TMODU')->get()->all();
+        //se consultan los submodulos de cada modulo
+        foreach($modules as $module){
+            $submodules = DB::table('S002V01TSUBM')->where('SUBM_IDMO', '=', $module->MODU_IDMO)->get()->all();
+            $permissionsPerSubmodule = [];
+            foreach($submodules as $submodule){
+                //Se consultan los menus
+                $menus = DB::table('S002V01TMENU')->where([
+                    ['MENU_IDMO', '=', $module->MODU_IDMO],
+                    ['MENU_IDSM', '=', $submodule->SUBM_IDSM],
+                ])->get()->all();
+
+                $permissionsPerMenu = [];
+                foreach($menus as $menu){
+                    $permissionsPerMenu[] = [
+                        'id' => $menu->MENU_IDME,
+                        'name' => $menu-> MENU_NOMB,
+                        'enabled' => 'N'
+                    ];
+                }
+
+                $permissionsPerSubmodule[] = [
+                    'id' => $submodule->SUBM_IDSM,
+                    'name' => $submodule->SUBM_NOMB,
+                    'enabled' => 'N',
+                    'children' => $permissionsPerMenu,
+                ];
+            }
+
+            $permissions[] = [
+                'id' => $module->MODU_IDMO,
+                'name' => $module->MODU_NOMO,
+                'enabled' => 'N',
+                'children' => $permissionsPerSubmodule
+            ];
+        }
+
+        $permissionsF['permissions'] = $permissions;
+        foreach($permissions as $k=>$v){
+            if(array_key_exists($k, $profileInfo['permissions'])){
+                $permissionsF['permissions'][$k] = $profileInfo['permissions'][$k];
+
+                foreach($v['children'] as $k0=>$v0){
+                    if(array_key_exists($k0, $profileInfo['permissions'][$k]['children'])){
+                        $permissionsF['permissions'][$k]['children'][$k0] = $profileInfo['permissions'][$k]['children'][$k0];
+
+                        foreach($v0['children'] as $k1=>$v1){
+                            if(array_key_exists($k1, $profileInfo['permissions'][$k]['children'][$k0]['children'])){
+                                $permissionsF['permissions'][$k]['children'][$k0]['children'][$k1] = $profileInfo['permissions'][$k]['children'][$k0]['children'][$k1];
+                            }else{
+                                $permissionsF['permissions'][$k]['children'][$k0]['children'][$k1] = $v1;
+                            }
+                        }
+                    }else{
+                        $permissionsF['permissions'][$k]['children'][$k0] = $v0;
+                    }
+                }
+            }
+        }
+
+        $profile->PERMISOS = $permissionsF;
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
         
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
         return $this->responseController->makeresponse(false, "EXITO", $profile);
     }
 
     public function updateUser(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
             'id' => 'required|string',
             'name' => 'required|string|max:50',
             'fApe' => 'required|string|max:50',
             'email' => 'required|string|email',
             'perf' => 'required|integer',
+            'id_user' => 'required|string',
+            'linea' => 'required|integer'
         ]);
 
         if($validator->fails()){
@@ -110,28 +223,59 @@ class UsersProfilesController extends Controller{
         }
 
         $user = $request->all();
+        $idUser = $this->encryptionController->decrypt($user['id']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
+        }
+
+        $idUserMod = $this->encryptionController->decrypt($user['id_user']);
+        if(!$idUserMod){
+            return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
+        }
+
+        if($idUser == $idUserMod){
+            return $this->responseController->makeResponse(true, "El usuario no puede modificar su propio registro.", [], 401);
+        }
+
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $correos = DB::table('S002V01TUSUA')->where([
+            ['USUA_COEL', '=', $user['email']],
+            ['USUA_IDUS', '!=', $idUser]
+        ])->get()->all();
+
+        if(count($correos) > 0){
+            return $this->responseController->makeResponse(true, "El nuevo correo electrónico ya está registrado en la base.", [], 401);
+        }
 
-        try{
-            DB::table('users')->where('id', '=', $user['id'])->update([
-                'name' => $user['name'],
-                'fLastName' => $user['fApe'],
-                'sLastName' => array_key_exists('sApe', $user) ? $user['sApe'] : null,
-                'email' => $user['email'],
-                'profile' => $user['perf']
-            ]);
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la actualización del usuario.", [], 500);
+        $perfil = DB::table('S002V01TPERF')->where('PERF_IDPE', '=', $user['perf'])->get()->first();
+        if(is_null($perfil)){
+            return $this->responseController->makeResponse(true, "El perfil asignado no existe.", [], 404);
         }
 
+        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
+            'USUA_NOMB' => $user['name'],
+            'USUA_APPA' => $user['fApe'],
+            'USUA_APMA' => array_key_exists('sApe', $user) ? $user['sApe'] : null,
+            'USUA_COEL' => $user['email'],
+            'USUA_PERF' => $user['perf'],
+            'USUA_USMO' => $idUserMod,
+            'USUA_FEMO' => $now
+        ]);
+
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUserMod, $now, $user['linea']);
         return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
     }
 
     public function createUser(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
             'name' => 'required|string|max:50',
             'fApe' => 'required|string|max:50',
-            'email' => 'required|string|email',
             'perf' => 'required|integer',
+            'email' => 'required|string|email',
             'password' => 'required|string|min:8|confirmed',
         ]);
 
@@ -147,54 +291,73 @@ class UsersProfilesController extends Controller{
         }
 
         $user = $request->all();
+        $idusre = $this->encryptionController->decrypt($user['id_user']);
 
-        try{
-            $userVer = DB::table('users')->where('email', '=', $user['email'])->get()->first();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+        if(!$idusre){
+            return $this->responseController->makeResponse(true, "El ID del usuario que registra no está encriptado correctamente.", [], 400);
         }
 
-        if($userVer){
-            return $this->responseController->makeResponse(true, "El correo electrónico ya se encuentra registrado en la base.", [], 401);
+        $usre = DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idusre)->get()->first();
+        if(is_null($usre)){
+            return $this->responseController->makeResponse(true, "El usuario que realiza el registro no existe.", [], 404);
+        }else if($usre->USUA_ESTA == 'Eliminado'){
+            return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
+        }else if($usre->USUA_ESTA == 'Inactivo'){
+            return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
         }
 
-        try{
-            $lastID = DB::table('users')->orderByDesc('id')->limit(1)->get()->first();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+        $email = DB::table('S002V01TUSUA')->where('USUA_COEL', '=', $user['email'])->get()->first();
+        if(!is_null($email)){
+            return $this->responseController->makeResponse(true, "El correo electrónico ya se encuentra registrado.", [], 401);
         }
 
-        $idNum = intval(substr($lastID->id, 3));
-        $idNum++;
-
-        $idUsr = "SAM";
-        if($idNum < 10) $idUsr .= "00$idNum";
-        else if($idNum < 100) $idUsr .= "0$idNum";
-        else $idUsr .= "$idNum";
-
-        $pass = Hash::make($user['password']);
-        
-        try{
-            DB::table('users')->insert([
-                'id' => $idUsr,
-                'name' => $user['name'],
-                'fLastName' => $user['fApe'],
-                'sLastName' => array_key_exists('sApe', $user) ? $user['sApe'] : null,
-                'profile' => $user['perf'],
-                'email' => $user['email'],
-                'password' => $pass,
-            ]);
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la inserción del usuario a la base.", [], 500);
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $idUser = $this->functionsController->uuidv5('1546058f-5a25-4334-85ae-e68f2a44bbaf', $user['email'] . $now);
+        $idExist = false;
+
+        do{
+            $exist = DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->get()->first();
+            if(!is_null($exist)){
+                $idExist = true;
+                $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+                $idUser = $this->functionsController->uuidv5('1546058f-5a25-4334-85ae-e68f2a44bbaf', $user['email'] . $now);
+            }else{
+                $idExist = false;
+            }
+        }while($idExist);
+
+        $perf = DB::table('S002V01TPERF')->where('PERF_IDPE', '=', $user['perf'])->get()->first();
+        if(is_null($perf)){
+            return $this->responseController->makeResponse(true, "El perfil asignado no existe.", [], 404);
         }
 
+        $passEnc = Hash::make($user['password']);
+
+        DB::table('S002V01TUSUA')->insert([
+            'USUA_NULI' => $user['linea'],
+            'USUA_IDUS' => $idUser,
+            'USUA_NOMB' => $user['name'],
+            'USUA_APPA' => $user['fApe'],
+            'USUA_APMA' => array_keys($user, 'sApe') ? $user['sApe'] : null,
+            'USUA_PERF' => $user['perf'],
+            'USUA_CONT' => $passEnc,
+            'USUA_COEL' => $user['email'],
+            'USUA_USRE' => $idusre,
+            'USUA_FERE' => $now,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idusre, $now, $user['linea']);
         return $this->responseController->makeResponse(false, "EXITO: Registro correcto.");
     }
 
     public function blockUser(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
             'id' => 'required|string',
-            'estatus' => 'required|in:Activo,Inactivo'
+            'estatus' => 'required|in:Activo,Inactivo',
+            'id_user' => 'required|string',
+            'linea' => 'required|integer'
         ]);
 
         if($validator->fails()){
@@ -209,22 +372,39 @@ class UsersProfilesController extends Controller{
         }
 
         $user = $request->all();
+        $idUser = $this->encryptionController->decrypt($user['id']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
+        }
+
+        $idUserMod = $this->encryptionController->decrypt($user['id_user']);
+        if(!$idUserMod){
+            return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
+        }
 
-        try{
-            DB::table('users')->where('id', '=', $user['id'])->update([
-                'status' => $user['estatus']
-            ]);
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la actualización del usuario.", [], 500);
+        if($idUser == $idUserMod){
+            return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo", [], 400);
         }
 
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
+            'USUA_ESTA' => $user['estatus'],
+            'USUA_USMO' => $idUserMod,
+            'USUA_FEMO' => $now
+        ]);
+
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUserMod, $now, $user['linea']);
         return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
     }
 
     public function updatePass(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
             'id' => 'required|string',
             'password' => 'required|string|min:8|confirmed',
+            'id_user' => 'required|string',
+            'linea' => 'required|integer'
         ]);
 
         if($validator->fails()){
@@ -239,36 +419,50 @@ class UsersProfilesController extends Controller{
         }
 
         $user = $request->all();
-        $newPass = Hash::make($user['password']);
+        $idUser = $this->encryptionController->decrypt($user['id']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
+        }
 
-        try{
-            $usr = DB::table('users')->select('password')->where('id', '=', $user['id'])->get()->first();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+        $idUserMod = $this->encryptionController->decrypt($user['id_user']);
+        if(!$idUserMod){
+            return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
         }
 
-        if(is_null($usr)){
+        if($idUser == $idUserMod){
+            return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo.", [], 401);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->get()->first();
+        if(!$usr){
             return $this->responseController->makeResponse(true, "El usuario consultado no existe.", [], 404);
         }
 
-        if(Hash::check($user['password'], $usr->password)){
+        $lastPass = $usr->USUA_CONT;
+        if(Hash::check($user['password'], $lastPass)){
             return $this->responseController->makeResponse(true, "La contraseña nueva es igual a la anterior.", [], 401);
         }
 
-        try{
-            DB::table('users')->where('id', '=', $user['id'])->update([
-                'password' => $newPass
-            ]);
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la actualización del usuario.", [], 500);
-        }
+        $newPass = Hash::make($user['password']);
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
+            'USUA_CONT' => $newPass,
+            'USUA_USMO' => $idUserMod,
+            'USUA_FEMO' => $now
+        ]);
 
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUserMod, $now, $user['linea']);
         return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
     }
 
     public function deleteUser(Request $request){
+        DB::enableQueryLog();
         $validator = Validator::make($request->all(), [
             'id' => 'required|string',
+            'id_user' => 'required|string',
+            'linea' => 'required|integer'
         ]);
 
         if($validator->fails()){
@@ -283,28 +477,285 @@ class UsersProfilesController extends Controller{
         }
 
         $user = $request->all();
+        $idUser = $this->encryptionController->decrypt($user['id']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El id del usuario que desea eliminar no está encriptado correctamente", [], 400);
+        }
 
-        try{
-            DB::table('users')->where('id', '=', $user['id'])->update([
-                'status' => 'Eliminado'
-            ]);
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la actualización del usuario.", [], 500);
+        $idUserMod = $this->encryptionController->decrypt($user['id_user']);
+        if(!$idUserMod){
+            return $this->responseController->makeResponse(true, "El id del usuario que elimina no está encriptado correctamente", [], 400);
         }
 
+        if($idUser == $idUserMod){
+            return $this->responseController->makeResponse(true, "El usuario no puede eliminarse a sí mismo", [], 401);
+        }
+
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
+            'USUA_ESTA' => 'Eliminado',
+            'USUA_USMO' => $idUserMod,
+            'USUA_FEMO' => $now
+        ]);
+
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUserMod, $now, $user['linea']);
         return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
     }
 
-    public function getModules(){
-        try{
-            $modules = DB::table('modules')->select(
-                'id as IDMODULO',
-                'name as NOMBREMODULO'
-            )->get();
-        }catch(PDOException $e){
-            return $this->responseController->makeResponse(true, "No se pudo realizar la consulta a la base.", [], 500);
+    public function getModules($idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
         }
         
+        $modules = DB::table('S002V01TMODU')->select(
+            'MODU_IDMO as IDMODULO',
+            'MODU_NOMO as NOMBREMODULO'
+        )->get();
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
         return $this->responseController->makeresponse(false, "EXITO", $modules);
     }
+
+    public function getSubmodules($module, $idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $module = $this->encryptionController->decrypt($module);
+        if(!$module){
+            return $this->responseController->makeResponse(true, "El módulo no está encriptado correctamente", [], 400);
+        }
+
+        $submodules = DB::table('S002V01TSUBM')->select(
+            'SUBM_IDSM as IDSUBMODULO',
+            'SUBM_NOMB as NOMBRESUBMODULO',
+            'SUBM_ICON AS ICONOSUBMODULO'
+        )->where('SUBM_IDMO', '=', $module)->get();
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeresponse(false, "EXITO", $submodules);
+    }
+
+    public function getMenus($module, $submodule, $idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $module = $this->encryptionController->decrypt($module);
+        $submodule = $this->encryptionController->decrypt($submodule);
+
+        if(!$module){
+            return $this->responseController->makeResponse(true, "El módulo no está encriptado correctamente", [], 400);
+        }else if(!$submodule){
+            return $this->responseController->makeResponse(true, "El submódulo no está encriptado correctamente", [], 400);
+        }
+
+        $menus = DB::table('S002V01TMENU')->select(
+            'MENU_IDME AS IDMENU',
+            'MENU_NOMB AS NOMBREMENU' 
+        )->where([
+            ['MENU_IDMO', '=', $module],
+            ['MENU_IDSM', '=', $submodule]
+        ])->get();
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeresponse(false, "EXITO", $menus);
+    }
+
+    public function buildInitialPermissions($idUser, $line){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->decrypt($idUser);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuaio que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $permissions = [];
+        //Se obtienen todos los modulos
+        $modules = DB::table('S002V01TMODU')->get()->all();
+        //se consultan los submodulos de cada modulo
+        foreach($modules as $module){
+            $submodules = DB::table('S002V01TSUBM')->where('SUBM_IDMO', '=', $module->MODU_IDMO)->get()->all();
+            $permissionsPerSubmodule = [];
+            foreach($submodules as $submodule){
+                //Se consultan los menus
+                $menus = DB::table('S002V01TMENU')->where([
+                    ['MENU_IDMO', '=', $module->MODU_IDMO],
+                    ['MENU_IDSM', '=', $submodule->SUBM_IDSM],
+                ])->get()->all();
+
+                $permissionsPerMenu = [];
+                foreach($menus as $menu){
+                    $permissionsPerMenu[] = [
+                        'id' => $menu->MENU_IDME,
+                        'name' => $menu-> MENU_NOMB,
+                        'enabled' => 'N'
+                    ];
+                }
+
+                $permissionsPerSubmodule[] = [
+                    'id' => $submodule->SUBM_IDSM,
+                    'name' => $submodule->SUBM_NOMB,
+                    'enabled' => 'N',
+                    'children' => $permissionsPerMenu,
+                ];
+            }
+
+            $permissions[] = [
+                'id' => $module->MODU_IDMO,
+                'name' => $module->MODU_NOMO,
+                'enabled' => 'N',
+                'children' => $permissionsPerSubmodule
+            ];
+        }
+
+        $actions = DB::getQueryLog();
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+
+        $this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeresponse(false, "EXITO", ['permissions' => $permissions]);
+    }
+
+    public function updateProfile(Request $request){
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+            'permissions' => 'required|json',
+            'name' => 'required|string|max:50',
+            'id_user' => 'required|string',
+            'linea' => 'required|integer'
+        ]);
+
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $info = $request->all();
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $idUser = $this->encryptionController->decrypt($info['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente", [], 401);
+        }
+
+        DB::table('S002V01TPERF')->where('PERF_IDPE', $info['id'])->update([
+            'PERF_PERM' => $info['permissions'],
+            'PERF_NOPE' => $info['name'],
+            'PERF_USMO' => $idUser,
+            'PERF_FEMO' => $now
+        ]);
+
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUser, $now, $info['linea']);
+        return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
+    }
+
+    public function deleteProfile(Request $request){
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+            'id_user' => 'required|string',
+            'linea' => 'required|integer'
+        ]);
+
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $profile = $request->all();
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $idUser = $this->encryptionController->decrypt($profile['id_user']);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, "El id del usuario que elimina no está encriptado correctamente", [], 401);
+        }
+
+        $users = DB::table('S002V01TUSUA')->where('USUA_PERF', '=', $profile['id'])->get()->all();
+        if(count($users) > 0){
+            return $this->responseController->makeResponse(true, "El perfil seleccionado no se puede eliminar porque hay usuarios asociados a él.", [], 401);
+        }
+        
+        DB::table('S002V01TPERF')->where('PERF_IDPE', $profile['id'])->update([
+            'PERF_ESTA' => 'Eliminado',
+            'PERF_USMO' => $idUser,
+            'PERF_FEMO' => $now
+        ]);
+
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUser, $now, $profile['linea']);
+        return $this->responseController->makeResponse(false, "EXITO: Eliminación correcta.");
+    }
+
+    public function createProfile(Request $request){
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'name' => 'required|string|min:8|max:50',
+            'permissions' => 'required|json'
+        ]);
+
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $profile = $request->all();
+        $now = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $idUser = $this->encryptionController->decrypt($profile['id_user']);
+
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El perfil no está encriptado correctamente.', [], 401);
+        }
+
+        DB::table('S002V01TPERF')->insert([
+            'PERF_NULI' => $profile['linea'],
+            'PERF_NOPE' => $profile['name'],
+            'PERF_PERM' => $profile['permissions'],
+            'PERF_USRE' => $idUser,
+            'PERF_FERE' => $now,
+        ]);
+        
+        $actions = DB::getQueryLog();
+        $this->functionsController->registerActivity($actions, $idUser, $now, $profile['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO');
+    }
 }

+ 8 - 10
sistema-mantenimiento-back/app/Http/Middleware/JWTMiddleware.php

@@ -11,6 +11,7 @@ use Firebase\JWT\JWT;
 use Firebase\JWT\Key;
 
 use App\Http\Controllers\ResponseController;
+use Exception;
 
 class JWTMiddleware{
     private $responseController;
@@ -27,22 +28,18 @@ class JWTMiddleware{
     }
 
     public function handle(Request $request, Closure $next){
-        $auth = $request->header('Authorization');
-        if(is_null($auth)){
-            return $this->responseController->makeResponse(true, "No se encontró el token de autorización.", [], 401);
-        }else if(!str_contains($auth, "Bearer")){
+        $token = $request->bearerToken();
+        if(is_null($token)){
             return $this->responseController->makeResponse(true, "No se encontró el token de autorización.", [], 401);
         }
 
-        $token = str_replace("Bearer ", "", $auth);
-        if(strlen($token) < 200){
+        try{
+            $decoded = JWT::decode($token, new Key($this->publicKey, 'EdDSA'));
+        }catch(Exception $e){
             return $this->responseController->makeResponse(true, "Token inválido.", [], 401);
         }
 
-        $decoded = JWT::decode($token, new Key($this->publicKey, 'EdDSA'));
-        $now = Carbon::now('America/Mexico_city')->timestamp;
-
-        $usr = DB::table('users')->where('email', '=', $decoded->iss)->first();
+        $usr = DB::table('S002V01TUSUA')->where('USUA_COEL', '=', $decoded->iss)->first();
         if(is_null($usr)){
             return $this->responseController->makeResponse(true, "El usuario que generó el token no está registrado en la base.", [], 401);
         }
@@ -51,6 +48,7 @@ class JWTMiddleware{
             return $this->responseController->makeResponse(true, "El token no fue generado en este sistema.", [], 401);
         }
 
+        $now = Carbon::now('America/Mexico_city')->timestamp;
         if($now > $decoded->cad){
             return $this->responseController->makeResponse(true, "Token expirado.", [], 401);
         }

+ 1 - 2
sistema-mantenimiento-back/composer.json

@@ -10,8 +10,7 @@
         "guzzlehttp/guzzle": "^7.2",
         "laravel/framework": "^9.2",
         "laravel/sanctum": "^2.14.1",
-        "laravel/tinker": "^2.7",
-        "phpoffice/phpspreadsheet": "^1.22"
+        "laravel/tinker": "^2.7"
     },
     "require-dev": {
         "fakerphp/faker": "^1.9.1",

+ 47 - 440
sistema-mantenimiento-back/composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "1b63eef5c28dc96d1a3498aa73710af7",
+    "content-hash": "752c90f03ae46b1f7274a01f90165f75",
     "packages": [
         {
             "name": "brick/math",
@@ -437,57 +437,6 @@
             ],
             "time": "2021-10-11T09:18:27+00:00"
         },
-        {
-            "name": "ezyang/htmlpurifier",
-            "version": "v4.14.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/ezyang/htmlpurifier.git",
-                "reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/12ab42bd6e742c70c0a52f7b82477fcd44e64b75",
-                "reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75",
-                "shasum": ""
-            },
-            "require": {
-                "php": ">=5.2"
-            },
-            "type": "library",
-            "autoload": {
-                "files": [
-                    "library/HTMLPurifier.composer.php"
-                ],
-                "psr-0": {
-                    "HTMLPurifier": "library/"
-                },
-                "exclude-from-classmap": [
-                    "/library/HTMLPurifier/Language/"
-                ]
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "LGPL-2.1-or-later"
-            ],
-            "authors": [
-                {
-                    "name": "Edward Z. Yang",
-                    "email": "admin@htmlpurifier.org",
-                    "homepage": "http://ezyang.com"
-                }
-            ],
-            "description": "Standards compliant HTML filter written in PHP",
-            "homepage": "http://htmlpurifier.org/",
-            "keywords": [
-                "html"
-            ],
-            "support": {
-                "issues": "https://github.com/ezyang/htmlpurifier/issues",
-                "source": "https://github.com/ezyang/htmlpurifier/tree/v4.14.0"
-            },
-            "time": "2021-12-25T01:21:49+00:00"
-        },
         {
             "name": "firebase/php-jwt",
             "version": "v6.0.0",
@@ -1703,184 +1652,6 @@
             ],
             "time": "2021-11-21T11:48:40+00:00"
         },
-        {
-            "name": "maennchen/zipstream-php",
-            "version": "2.1.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/maennchen/ZipStream-PHP.git",
-                "reference": "c4c5803cc1f93df3d2448478ef79394a5981cc58"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/c4c5803cc1f93df3d2448478ef79394a5981cc58",
-                "reference": "c4c5803cc1f93df3d2448478ef79394a5981cc58",
-                "shasum": ""
-            },
-            "require": {
-                "myclabs/php-enum": "^1.5",
-                "php": ">= 7.1",
-                "psr/http-message": "^1.0",
-                "symfony/polyfill-mbstring": "^1.0"
-            },
-            "require-dev": {
-                "ext-zip": "*",
-                "guzzlehttp/guzzle": ">= 6.3",
-                "mikey179/vfsstream": "^1.6",
-                "phpunit/phpunit": ">= 7.5"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "ZipStream\\": "src/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Paul Duncan",
-                    "email": "pabs@pablotron.org"
-                },
-                {
-                    "name": "Jonatan Männchen",
-                    "email": "jonatan@maennchen.ch"
-                },
-                {
-                    "name": "Jesse Donat",
-                    "email": "donatj@gmail.com"
-                },
-                {
-                    "name": "András Kolesár",
-                    "email": "kolesar@kolesar.hu"
-                }
-            ],
-            "description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
-            "keywords": [
-                "stream",
-                "zip"
-            ],
-            "support": {
-                "issues": "https://github.com/maennchen/ZipStream-PHP/issues",
-                "source": "https://github.com/maennchen/ZipStream-PHP/tree/master"
-            },
-            "funding": [
-                {
-                    "url": "https://opencollective.com/zipstream",
-                    "type": "open_collective"
-                }
-            ],
-            "time": "2020-05-30T13:11:16+00:00"
-        },
-        {
-            "name": "markbaker/complex",
-            "version": "3.0.1",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/MarkBaker/PHPComplex.git",
-                "reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/ab8bc271e404909db09ff2d5ffa1e538085c0f22",
-                "reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22",
-                "shasum": ""
-            },
-            "require": {
-                "php": "^7.2 || ^8.0"
-            },
-            "require-dev": {
-                "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
-                "phpcompatibility/php-compatibility": "^9.0",
-                "phpunit/phpunit": "^7.0 || ^8.0 || ^9.3",
-                "squizlabs/php_codesniffer": "^3.4"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "Complex\\": "classes/src/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Mark Baker",
-                    "email": "mark@lange.demon.co.uk"
-                }
-            ],
-            "description": "PHP Class for working with complex numbers",
-            "homepage": "https://github.com/MarkBaker/PHPComplex",
-            "keywords": [
-                "complex",
-                "mathematics"
-            ],
-            "support": {
-                "issues": "https://github.com/MarkBaker/PHPComplex/issues",
-                "source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.1"
-            },
-            "time": "2021-06-29T15:32:53+00:00"
-        },
-        {
-            "name": "markbaker/matrix",
-            "version": "3.0.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/MarkBaker/PHPMatrix.git",
-                "reference": "c66aefcafb4f6c269510e9ac46b82619a904c576"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/c66aefcafb4f6c269510e9ac46b82619a904c576",
-                "reference": "c66aefcafb4f6c269510e9ac46b82619a904c576",
-                "shasum": ""
-            },
-            "require": {
-                "php": "^7.1 || ^8.0"
-            },
-            "require-dev": {
-                "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
-                "phpcompatibility/php-compatibility": "^9.0",
-                "phpdocumentor/phpdocumentor": "2.*",
-                "phploc/phploc": "^4.0",
-                "phpmd/phpmd": "2.*",
-                "phpunit/phpunit": "^7.0 || ^8.0 || ^9.3",
-                "sebastian/phpcpd": "^4.0",
-                "squizlabs/php_codesniffer": "^3.4"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "Matrix\\": "classes/src/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Mark Baker",
-                    "email": "mark@demon-angel.eu"
-                }
-            ],
-            "description": "PHP Class for working with matrices",
-            "homepage": "https://github.com/MarkBaker/PHPMatrix",
-            "keywords": [
-                "mathematics",
-                "matrix",
-                "vector"
-            ],
-            "support": {
-                "issues": "https://github.com/MarkBaker/PHPMatrix/issues",
-                "source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.0"
-            },
-            "time": "2021-07-01T19:01:15+00:00"
-        },
         {
             "name": "monolog/monolog",
             "version": "2.4.0",
@@ -1980,66 +1751,6 @@
             ],
             "time": "2022-03-14T12:44:37+00:00"
         },
-        {
-            "name": "myclabs/php-enum",
-            "version": "1.8.3",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/myclabs/php-enum.git",
-                "reference": "b942d263c641ddb5190929ff840c68f78713e937"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/myclabs/php-enum/zipball/b942d263c641ddb5190929ff840c68f78713e937",
-                "reference": "b942d263c641ddb5190929ff840c68f78713e937",
-                "shasum": ""
-            },
-            "require": {
-                "ext-json": "*",
-                "php": "^7.3 || ^8.0"
-            },
-            "require-dev": {
-                "phpunit/phpunit": "^9.5",
-                "squizlabs/php_codesniffer": "1.*",
-                "vimeo/psalm": "^4.6.2"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "MyCLabs\\Enum\\": "src/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "PHP Enum contributors",
-                    "homepage": "https://github.com/myclabs/php-enum/graphs/contributors"
-                }
-            ],
-            "description": "PHP Enum implementation",
-            "homepage": "http://github.com/myclabs/php-enum",
-            "keywords": [
-                "enum"
-            ],
-            "support": {
-                "issues": "https://github.com/myclabs/php-enum/issues",
-                "source": "https://github.com/myclabs/php-enum/tree/1.8.3"
-            },
-            "funding": [
-                {
-                    "url": "https://github.com/mnapoli",
-                    "type": "github"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum",
-                    "type": "tidelift"
-                }
-            ],
-            "time": "2021-07-05T08:18:36+00:00"
-        },
         {
             "name": "nesbot/carbon",
             "version": "2.57.0",
@@ -2339,110 +2050,6 @@
             },
             "time": "2021-11-30T19:35:32+00:00"
         },
-        {
-            "name": "phpoffice/phpspreadsheet",
-            "version": "1.22.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
-                "reference": "3a9e29b4f386a08a151a33578e80ef1747037a48"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/3a9e29b4f386a08a151a33578e80ef1747037a48",
-                "reference": "3a9e29b4f386a08a151a33578e80ef1747037a48",
-                "shasum": ""
-            },
-            "require": {
-                "ext-ctype": "*",
-                "ext-dom": "*",
-                "ext-fileinfo": "*",
-                "ext-gd": "*",
-                "ext-iconv": "*",
-                "ext-libxml": "*",
-                "ext-mbstring": "*",
-                "ext-simplexml": "*",
-                "ext-xml": "*",
-                "ext-xmlreader": "*",
-                "ext-xmlwriter": "*",
-                "ext-zip": "*",
-                "ext-zlib": "*",
-                "ezyang/htmlpurifier": "^4.13",
-                "maennchen/zipstream-php": "^2.1",
-                "markbaker/complex": "^3.0",
-                "markbaker/matrix": "^3.0",
-                "php": "^7.3 || ^8.0",
-                "psr/http-client": "^1.0",
-                "psr/http-factory": "^1.0",
-                "psr/simple-cache": "^1.0"
-            },
-            "require-dev": {
-                "dealerdirect/phpcodesniffer-composer-installer": "dev-master",
-                "dompdf/dompdf": "^1.0",
-                "friendsofphp/php-cs-fixer": "^3.2",
-                "jpgraph/jpgraph": "^4.0",
-                "mpdf/mpdf": "8.0.17",
-                "phpcompatibility/php-compatibility": "^9.3",
-                "phpstan/phpstan": "^1.1",
-                "phpstan/phpstan-phpunit": "^1.0",
-                "phpunit/phpunit": "^8.5 || ^9.0",
-                "squizlabs/php_codesniffer": "^3.6",
-                "tecnickcom/tcpdf": "^6.4"
-            },
-            "suggest": {
-                "dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
-                "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
-                "mpdf/mpdf": "Option for rendering PDF with PDF Writer",
-                "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Maarten Balliauw",
-                    "homepage": "https://blog.maartenballiauw.be"
-                },
-                {
-                    "name": "Mark Baker",
-                    "homepage": "https://markbakeruk.net"
-                },
-                {
-                    "name": "Franck Lefevre",
-                    "homepage": "https://rootslabs.net"
-                },
-                {
-                    "name": "Erik Tilt"
-                },
-                {
-                    "name": "Adrien Crivelli"
-                }
-            ],
-            "description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
-            "homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
-            "keywords": [
-                "OpenXML",
-                "excel",
-                "gnumeric",
-                "ods",
-                "php",
-                "spreadsheet",
-                "xls",
-                "xlsx"
-            ],
-            "support": {
-                "issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
-                "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.22.0"
-            },
-            "time": "2022-02-18T12:57:07+00:00"
-        },
         {
             "name": "phpoption/phpoption",
             "version": "1.8.1",
@@ -2829,25 +2436,25 @@
         },
         {
             "name": "psr/simple-cache",
-            "version": "1.0.1",
+            "version": "3.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/php-fig/simple-cache.git",
-                "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
+                "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
-                "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
+                "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865",
+                "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865",
                 "shasum": ""
             },
             "require": {
-                "php": ">=5.3.0"
+                "php": ">=8.0.0"
             },
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "1.0.x-dev"
+                    "dev-master": "3.0.x-dev"
                 }
             },
             "autoload": {
@@ -2862,7 +2469,7 @@
             "authors": [
                 {
                     "name": "PHP-FIG",
-                    "homepage": "http://www.php-fig.org/"
+                    "homepage": "https://www.php-fig.org/"
                 }
             ],
             "description": "Common interfaces for simple caching",
@@ -2874,9 +2481,9 @@
                 "simple-cache"
             ],
             "support": {
-                "source": "https://github.com/php-fig/simple-cache/tree/master"
+                "source": "https://github.com/php-fig/simple-cache/tree/3.0.0"
             },
-            "time": "2017-10-23T01:57:42+00:00"
+            "time": "2021-10-29T13:26:27+00:00"
         },
         {
             "name": "psy/psysh",
@@ -3179,16 +2786,16 @@
         },
         {
             "name": "symfony/console",
-            "version": "v6.0.7",
+            "version": "v6.0.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/console.git",
-                "reference": "70dcf7b2ca2ea08ad6ebcc475f104a024fb5632e"
+                "reference": "3bebf4108b9e07492a2a4057d207aa5a77d146b1"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/console/zipball/70dcf7b2ca2ea08ad6ebcc475f104a024fb5632e",
-                "reference": "70dcf7b2ca2ea08ad6ebcc475f104a024fb5632e",
+                "url": "https://api.github.com/repos/symfony/console/zipball/3bebf4108b9e07492a2a4057d207aa5a77d146b1",
+                "reference": "3bebf4108b9e07492a2a4057d207aa5a77d146b1",
                 "shasum": ""
             },
             "require": {
@@ -3254,7 +2861,7 @@
                 "terminal"
             ],
             "support": {
-                "source": "https://github.com/symfony/console/tree/v6.0.7"
+                "source": "https://github.com/symfony/console/tree/v6.0.5"
             },
             "funding": [
                 {
@@ -3270,7 +2877,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2022-03-31T17:18:25+00:00"
+            "time": "2022-02-25T10:48:52+00:00"
         },
         {
             "name": "symfony/css-selector",
@@ -3339,16 +2946,16 @@
         },
         {
             "name": "symfony/deprecation-contracts",
-            "version": "v3.0.1",
+            "version": "v3.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/deprecation-contracts.git",
-                "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c"
+                "reference": "c726b64c1ccfe2896cb7df2e1331c357ad1c8ced"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c",
-                "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c",
+                "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/c726b64c1ccfe2896cb7df2e1331c357ad1c8ced",
+                "reference": "c726b64c1ccfe2896cb7df2e1331c357ad1c8ced",
                 "shasum": ""
             },
             "require": {
@@ -3386,7 +2993,7 @@
             "description": "A generic function and convention to trigger deprecation notices",
             "homepage": "https://symfony.com",
             "support": {
-                "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.1"
+                "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.0"
             },
             "funding": [
                 {
@@ -3402,7 +3009,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2022-01-02T09:55:41+00:00"
+            "time": "2021-11-01T23:48:49+00:00"
         },
         {
             "name": "symfony/error-handler",
@@ -3560,16 +3167,16 @@
         },
         {
             "name": "symfony/event-dispatcher-contracts",
-            "version": "v3.0.1",
+            "version": "v3.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/event-dispatcher-contracts.git",
-                "reference": "7bc61cc2db649b4637d331240c5346dcc7708051"
+                "reference": "aa5422287b75594b90ee9cd807caf8f0df491385"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/7bc61cc2db649b4637d331240c5346dcc7708051",
-                "reference": "7bc61cc2db649b4637d331240c5346dcc7708051",
+                "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/aa5422287b75594b90ee9cd807caf8f0df491385",
+                "reference": "aa5422287b75594b90ee9cd807caf8f0df491385",
                 "shasum": ""
             },
             "require": {
@@ -3619,7 +3226,7 @@
                 "standards"
             ],
             "support": {
-                "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.0.1"
+                "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.0.0"
             },
             "funding": [
                 {
@@ -3635,7 +3242,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2022-01-02T09:55:41+00:00"
+            "time": "2021-07-15T12:33:35+00:00"
         },
         {
             "name": "symfony/finder",
@@ -4840,16 +4447,16 @@
         },
         {
             "name": "symfony/service-contracts",
-            "version": "v3.0.1",
+            "version": "v3.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/service-contracts.git",
-                "reference": "e517458f278c2131ca9f262f8fbaf01410f2c65c"
+                "reference": "36715ebf9fb9db73db0cb24263c79077c6fe8603"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/service-contracts/zipball/e517458f278c2131ca9f262f8fbaf01410f2c65c",
-                "reference": "e517458f278c2131ca9f262f8fbaf01410f2c65c",
+                "url": "https://api.github.com/repos/symfony/service-contracts/zipball/36715ebf9fb9db73db0cb24263c79077c6fe8603",
+                "reference": "36715ebf9fb9db73db0cb24263c79077c6fe8603",
                 "shasum": ""
             },
             "require": {
@@ -4902,7 +4509,7 @@
                 "standards"
             ],
             "support": {
-                "source": "https://github.com/symfony/service-contracts/tree/v3.0.1"
+                "source": "https://github.com/symfony/service-contracts/tree/v3.0.0"
             },
             "funding": [
                 {
@@ -4918,7 +4525,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2022-03-13T20:10:05+00:00"
+            "time": "2021-11-04T17:53:12+00:00"
         },
         {
             "name": "symfony/string",
@@ -5102,16 +4709,16 @@
         },
         {
             "name": "symfony/translation-contracts",
-            "version": "v3.0.1",
+            "version": "v3.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/translation-contracts.git",
-                "reference": "c4183fc3ef0f0510893cbeedc7718fb5cafc9ac9"
+                "reference": "1b6ea5a7442af5a12dba3dbd6d71034b5b234e77"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/c4183fc3ef0f0510893cbeedc7718fb5cafc9ac9",
-                "reference": "c4183fc3ef0f0510893cbeedc7718fb5cafc9ac9",
+                "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/1b6ea5a7442af5a12dba3dbd6d71034b5b234e77",
+                "reference": "1b6ea5a7442af5a12dba3dbd6d71034b5b234e77",
                 "shasum": ""
             },
             "require": {
@@ -5160,7 +4767,7 @@
                 "standards"
             ],
             "support": {
-                "source": "https://github.com/symfony/translation-contracts/tree/v3.0.1"
+                "source": "https://github.com/symfony/translation-contracts/tree/v3.0.0"
             },
             "funding": [
                 {
@@ -5176,7 +4783,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2022-01-02T09:55:41+00:00"
+            "time": "2021-09-07T12:43:40+00:00"
         },
         {
             "name": "symfony/var-dumper",
@@ -6346,16 +5953,16 @@
         },
         {
             "name": "phpdocumentor/type-resolver",
-            "version": "1.6.1",
+            "version": "1.6.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpDocumentor/TypeResolver.git",
-                "reference": "77a32518733312af16a44300404e945338981de3"
+                "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3",
-                "reference": "77a32518733312af16a44300404e945338981de3",
+                "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
+                "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
                 "shasum": ""
             },
             "require": {
@@ -6390,9 +5997,9 @@
             "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
             "support": {
                 "issues": "https://github.com/phpDocumentor/TypeResolver/issues",
-                "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1"
+                "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
             },
-            "time": "2022-03-15T21:29:03+00:00"
+            "time": "2022-01-04T19:58:01+00:00"
         },
         {
             "name": "phpspec/prophecy",
@@ -8186,7 +7793,7 @@
     "prefer-stable": true,
     "prefer-lowest": false,
     "platform": {
-        "php": "^8.1"
+        "php": "^8.0.2"
     },
     "platform-dev": [],
     "plugin-api-version": "2.2.0"

+ 19 - 6
sistema-mantenimiento-back/routes/api.php

@@ -19,6 +19,8 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
 });
 
 Route::post("/login", "App\Http\Controllers\LoginController@login");
+Route::post("/pass", "App\Http\Controllers\LoginController@createPasword");
+Route::post("/verify-token", "App\Http\Controllers\LoginController@verifyToken");
 
 Route::middleware(['jwt.auth', 'cors'])->group(function(){
     //Módulo de usuarios y perfiles
@@ -27,12 +29,23 @@ Route::middleware(['jwt.auth', 'cors'])->group(function(){
     Route::post("/modify-user", "App\Http\Controllers\UsersProfilesController@updateUser");    //F
     Route::post("/modify-pass", "App\Http\Controllers\UsersProfilesController@updatePass");    //F
     Route::post("/block-user", "App\Http\Controllers\UsersProfilesController@blockUser");      //F
-    Route::get("/get-users", "App\Http\Controllers\UsersProfilesController@getUsers");         //F
-    Route::get("/get-user/{id}", "App\Http\Controllers\UsersProfilesController@getUser");      //F
-    Route::get("/get-profiles", "App\Http\Controllers\UsersProfilesController@getProfiles");   //F
-    Route::get("/get-profile/{id}", "App\Http\Controllers\UsersProfilesController@getProfile");//F
-    Route::get("/get-modules", "App\Http\Controllers\UsersProfilesController@getModules");
+    Route::post("/modify-profile", "App\Http\Controllers\UsersProfilesController@updateProfile");
+    Route::post("/create-profile", "App\Http\Controllers\UsersProfilesController@createProfile");
+    Route::post("/delete-profile", "App\Http\Controllers\UsersProfilesController@deleteProfile");
+    Route::get("/get-users/{id}/{line}", "App\Http\Controllers\UsersProfilesController@getUsers");         //F
+    Route::get("/get-user/{id}/{idUser}/{line}", "App\Http\Controllers\UsersProfilesController@getUser");      //F
+    Route::get("/get-profiles/{id}/{line}", "App\Http\Controllers\UsersProfilesController@getProfiles");   //F
+    Route::get("/get-profile/{id}/{idUser}/{line}", "App\Http\Controllers\UsersProfilesController@getProfile");//F
+    Route::get("/get-modules/{id}/{line}", "App\Http\Controllers\UsersProfilesController@getModules");
+    Route::get("/get-submodules/{module}/{id}/{line}", "App\Http\Controllers\UsersProfilesController@getSubmodules");
+    Route::get("/get-menus/{module}/{submodule}/{id}/{line}", "App\Http\Controllers\UsersProfilesController@getMenus");
+    Route::get("/get-initial-permissions/{id}/{line}", "App\Http\Controllers\UsersProfilesController@buildInitialPermissions");
     //Módulo administrador del sistema
-    Route::get("/get-last-connections", "App\Http\Controllers\SystemAdministratorController@getLastConnections");
+    Route::get("/get-last-connections/{id}/{line}", "App\Http\Controllers\SystemAdministratorController@getLastConnections");
+    Route::get("/get-catalogues/{id}/{line}", "App\Http\Controllers\SystemAdministratorController@getCatalogues");
+    Route::get("/get-user-connections/{id}/{idUser}/{line}", "App\Http\Controllers\SystemAdministratorController@getUserConnections");
+    Route::get("/get-last-actions/{id}/{line}", "App\Http\Controllers\SystemAdministratorController@getLastActions");
+    Route::get("/get-user-actions/{id}/{idUser}/{line}", "App\Http\Controllers\SystemAdministratorController@getUserActions");
     Route::post("/set-last-connection", "App\Http\Controllers\SystemAdministratorController@setLastConnection");
+    Route::post("/upload-catalogue", "App\Http\Controllers\SystemAdministratorController@registerCatalogue");
 });