ソースを参照

API IP Removida

JeanBenitez 3 年 前
コミット
22842a4f89
2 ファイル変更102 行追加88 行削除
  1. 22 0
      vacaciones/.vscode/settings.json
  2. 80 88
      vacaciones/src/app/services/iam/iam.service.ts

+ 22 - 0
vacaciones/.vscode/settings.json

@@ -0,0 +1,22 @@
+{
+    "workbench.colorCustomizations": {
+        "activityBar.activeBackground": "#ff6433",
+        "activityBar.activeBorder": "#00ff3d",
+        "activityBar.background": "#ff6433",
+        "activityBar.foreground": "#15202b",
+        "activityBar.inactiveForeground": "#15202b99",
+        "activityBarBadge.background": "#00ff3d",
+        "activityBarBadge.foreground": "#15202b",
+        "sash.hoverBorder": "#ff6433",
+        "statusBar.background": "#ff3d00",
+        "statusBar.foreground": "#e7e7e7",
+        "statusBarItem.hoverBackground": "#ff6433",
+        "statusBarItem.remoteBackground": "#ff3d00",
+        "statusBarItem.remoteForeground": "#e7e7e7",
+        "titleBar.activeBackground": "#ff3d00",
+        "titleBar.activeForeground": "#e7e7e7",
+        "titleBar.inactiveBackground": "#ff3d0099",
+        "titleBar.inactiveForeground": "#e7e7e799"
+    },
+    "peacock.color": "#ff3d00"
+}

+ 80 - 88
vacaciones/src/app/services/iam/iam.service.ts

@@ -30,9 +30,7 @@ export class IAMService implements OnInit {
     public setUserStorage: LocalstorageService,
     private adminGuard: AdminGuard,
     private userGuard: UserGuard
-  ) {
-    this.getIPAddress();
-  }
+  ) {}
   ngOnInit(): void {}
 
   public usuario_rfc: string = '';
@@ -40,95 +38,77 @@ export class IAMService implements OnInit {
   private ipAddress: string = '';
 
   async login(data: IAMInterface, solicitud_datos: string) {
-    if (this.ipAddress != '') {
-      let objeto = {
-        email: data.email.trim(),
-        password: data.password.trim(),
-        ip_address: this.ipAddress,
-      };
-
-      let respuesta = this.http
-        .post<ResponseLogin>(`${this._url}/login`, objeto)
-        .toPromise();
-      await respuesta.then(
-        async (data) => {
-          if (!data?.error) {
-            let status = this._encService.desencriptar(data!.response.ESTATUS);
-            let perfil = this._encService.desencriptar(data!.response.PERFIL);
-            let rfc_empresa_user = this._encService.desencriptar(data!.response.RFCEMPRESA);
-
-            let rfc_local = localStorage.getItem('RFCEMPRESA')!;
-            if (rfc_local.length > 13) {
-              await this._encService.desencriptar2(rfc_local).then(
-                (data:string) => rfc_local = data,
-                (error:any)=> console.log(error)
-              );
-            }
-            
-            if (rfc_empresa_user == rfc_local ) {
-              switch (status) {
-                case 'Activo':
-                  
-                  this.current_user = JSON.stringify(data!.response);
-                  this.jwt = data!.response.TOKEN;
-                  
-                  localStorage.setItem('jwt', data!.response.TOKEN);
-                  localStorage.setItem('TIMUSERENC',JSON.stringify(data?.response));
-
-                  let rfC_empresa_user = data?.response.RFCEMPRESA.replace('"', '').replace('"', '');
-                  localStorage.setItem('RFCEMPRESA', rfC_empresa_user!);
-                  this.userType(perfil, solicitud_datos);
-
-                  break;
-                case 'Eliminado':
-                  this.snackAlert('El usuario no existe');
-                  break;
-                case 'Inactivo':
-                  this.snackAlert('El usuario esta bloqueado');
-                  break;
-                default:
-                  this.snackAlert('Usuario inexistente');
-                  break;
-              }
-            } else {
-              this.snackAlert(
-                'El R.F.C. del usuario no coincide con el R.F.C. del sistema al que desea entrar'
-              );
+    let objeto = {
+      email: data.email.trim(),
+      password: data.password.trim(),
+    };
+
+    let respuesta = this.http
+      .post<ResponseLogin>(`${this._url}/login`, objeto)
+      .toPromise();
+    await respuesta.then(
+      async (data) => {
+        if (!data?.error) {
+          let status = this._encService.desencriptar(data!.response.ESTATUS);
+          let perfil = this._encService.desencriptar(data!.response.PERFIL);
+          let rfc_empresa_user = this._encService.desencriptar(
+            data!.response.RFCEMPRESA
+          );
+
+          let rfc_local = localStorage.getItem('RFCEMPRESA')!;
+          if (rfc_local.length > 13) {
+            await this._encService.desencriptar2(rfc_local).then(
+              (data: string) => (rfc_local = data),
+              (error: any) => console.log(error)
+            );
+          }
+
+          if (rfc_empresa_user == rfc_local) {
+            switch (status) {
+              case 'Activo':
+                this.current_user = JSON.stringify(data!.response);
+                this.jwt = data!.response.TOKEN;
+
+                localStorage.setItem('jwt', data!.response.TOKEN);
+                localStorage.setItem(
+                  'TIMUSERENC',
+                  JSON.stringify(data?.response)
+                );
+
+                let rfC_empresa_user = data?.response.RFCEMPRESA.replace(
+                  '"',
+                  ''
+                ).replace('"', '');
+                localStorage.setItem('RFCEMPRESA', rfC_empresa_user!);
+                this.userType(perfil, solicitud_datos);
+
+                break;
+              case 'Eliminado':
+                this.snackAlert('El usuario no existe');
+                break;
+              case 'Inactivo':
+                this.snackAlert('El usuario esta bloqueado');
+                break;
+              default:
+                this.snackAlert('Usuario inexistente');
+                break;
             }
           } else {
-            this.snackAlert(data.msg);
-          }
-        },
-        (error) => {
-          if (!error.ok) {
-            this.snackAlert('Ocurrió un error inesperado');
-          }
-          if (error.error.msg != undefined) {
-            this.snackAlert(error.error.msg);
-          }
-          if (error.status == 408) {
-            this.snackAlert('Conexion lenta');
+            this.snackAlert(
+              'El R.F.C. del usuario no coincide con el R.F.C. del sistema al que desea entrar'
+            );
           }
+        } else {
+          this.snackAlert(data.msg);
         }
-      );
-    }
-  }
-
-  private snackAlert(mensaje: string) {
-    this._snackBar.open(mensaje, 'Cerrar', {
-      duration: 4000,
-    });
-  }
-
-  private getIPAddress() {
-    this.http.get('https://api.ipify.org?format=json').subscribe(
-      (res: any) => {
-        this.ipAddress = res.ip;
       },
       (error) => {
         if (!error.ok) {
           this.snackAlert('Ocurrió un error inesperado');
         }
+        if (error.error.msg != undefined) {
+          this.snackAlert(error.error.msg);
+        }
         if (error.status == 408) {
           this.snackAlert('Conexion lenta');
         }
@@ -136,11 +116,21 @@ export class IAMService implements OnInit {
     );
   }
 
+  private snackAlert(mensaje: string) {
+    this._snackBar.open(mensaje, 'Cerrar', {
+      duration: 4000,
+    });
+  }
+
   public logout(): void {
     clearInterval(this.adminGuard.aux_test);
     clearInterval(this.userGuard.aux_test);
-    let rfc_empresa_local = localStorage.getItem("RFCEMPRESA")!;
-    if (rfc_empresa_local === null || rfc_empresa_local === undefined || rfc_empresa_local === '') {
+    let rfc_empresa_local = localStorage.getItem('RFCEMPRESA')!;
+    if (
+      rfc_empresa_local === null ||
+      rfc_empresa_local === undefined ||
+      rfc_empresa_local === ''
+    ) {
       localStorage.setItem('RFCEMPRESA', 'ITTEC');
     }
     localStorage.removeItem('jwt');
@@ -151,12 +141,14 @@ export class IAMService implements OnInit {
   }
 
   private userType(perfil: string, solicitud_datos: string) {
-    
-    if (perfil == "1") {
+    if (perfil == '1') {
       if (solicitud_datos == '') {
         this.router.navigate(['/admin/mesmpr']);
       } else {
-        this.router.navigate(['/admin/mesmav',{solicitud_datos: solicitud_datos}]);
+        this.router.navigate([
+          '/admin/mesmav',
+          { solicitud_datos: solicitud_datos },
+        ]);
       }
     } else {
       if (solicitud_datos == '') {