|
|
@@ -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 == '') {
|