diff --git a/Frontend Angular 4/src/app/app-routing.module.ts b/Frontend Angular 4/src/app/app-routing.module.ts index 02db45e50352ad066764ea6527a4492725051345..2e6a3ff59157e9dadf0d4aeff5f8a81b879d38e8 100755 --- a/Frontend Angular 4/src/app/app-routing.module.ts +++ b/Frontend Angular 4/src/app/app-routing.module.ts @@ -6,12 +6,14 @@ import { AuthGuard } from "./shared/guards/auth.guard"; const routes: Routes = [ { path: "", - loadChildren: () => import('./layout/layout.module').then(m => m.LayoutModule), + loadChildren: () => + import("./layout/layout.module").then((m) => m.LayoutModule), canActivate: [AuthGuard], }, { path: "login", - loadChildren: () => import('./login/login.module').then(m => m.LoginModule), + loadChildren: () => + import("./login/login.module").then((m) => m.LoginModule), data: { language: navigator.language && @@ -23,23 +25,31 @@ const routes: Routes = [ }, { path: "es/login", - loadChildren: () => import('./login/login.module').then(m => m.LoginModule), + loadChildren: () => + import("./login/login.module").then((m) => m.LoginModule), data: { language: "es" }, }, { path: "en/login", - loadChildren: () => import('./login/login.module').then(m => m.LoginModule), + loadChildren: () => + import("./login/login.module").then((m) => m.LoginModule), data: { language: "en" }, }, { path: "not-found", - loadChildren: () => import('./not-found/not-found.module').then(m => m.NotFoundModule), + loadChildren: () => + import("./not-found/not-found.module").then((m) => m.NotFoundModule), }, { path: "**", redirectTo: "not-found" }, ]; @NgModule({ - imports: [RouterModule.forRoot(routes, { useHash: true, relativeLinkResolution: 'legacy' })], + imports: [ + RouterModule.forRoot(routes, { + useHash: true, + relativeLinkResolution: "legacy", + }), + ], exports: [RouterModule], }) export class AppRoutingModule {} diff --git a/Frontend Angular 4/src/app/layout/layout.component.ts b/Frontend Angular 4/src/app/layout/layout.component.ts index 2cd5a9785b89de1cfad83b5e50bd681ebaa1afed..48f2e159fc44d828b6c1a7524698b71412c8bb18 100755 --- a/Frontend Angular 4/src/app/layout/layout.component.ts +++ b/Frontend Angular 4/src/app/layout/layout.component.ts @@ -18,9 +18,9 @@ export class LayoutComponent implements OnInit { } ngOnInit() { if (this.router.url === "/") { - this.router.navigate([ - "/" + this.translateService.get("i18n.code").value + "/login", - ]); + this.translateService + .get("i18n.code") + .subscribe((res) => this.router.navigate(["/" + res + "/login"])); } } } diff --git a/Frontend Angular 4/src/app/not-found/not-found.component.ts b/Frontend Angular 4/src/app/not-found/not-found.component.ts index cf853e6a932f6b9a1f13103e581d1c9f5cfa5f86..6b46f945d5fd2674f729871c18efa344de069fb8 100755 --- a/Frontend Angular 4/src/app/not-found/not-found.component.ts +++ b/Frontend Angular 4/src/app/not-found/not-found.component.ts @@ -12,7 +12,9 @@ export class NotFoundComponent { constructor(public translate: TranslateService) { this.translateService = translate; - this.urlLogin = - "/" + this.translateService.get("i18n.code").value + "/login"; + + this.translateService.get("i18n.code").subscribe((res) => { + this.urlLogin = "/" + res + "/login"; + }); } } diff --git a/Frontend Angular 4/src/app/shared/components/header/header.component.ts b/Frontend Angular 4/src/app/shared/components/header/header.component.ts index 7eefc9c5443ab63c45cdcf410f2d03754a73c56c..359b3fbf741f5b9ff5618954a394e9062a26c349 100755 --- a/Frontend Angular 4/src/app/shared/components/header/header.component.ts +++ b/Frontend Angular 4/src/app/shared/components/header/header.component.ts @@ -37,10 +37,14 @@ export class HeaderComponent implements OnInit { } logout() { + // Se borra de la sesión la información del login + this.authService.logout(); + this.sessionService.reset(); this.ghciService.desconectarWS(); - this.router.navigate([ - "/" + this.translateService.get("i18n.code").value + "/login", - ]); + + this.translateService + .get("i18n.code") + .subscribe((res) => this.router.navigate(["/" + res + "/login"])); } } diff --git a/Frontend Angular 4/src/app/shared/guards/auth.guard.ts b/Frontend Angular 4/src/app/shared/guards/auth.guard.ts index 91de8903a9aff3f61296ab32a28d221b958e342f..5f9312068d18b6fe9db2f8c662bbd62c9da7567e 100755 --- a/Frontend Angular 4/src/app/shared/guards/auth.guard.ts +++ b/Frontend Angular 4/src/app/shared/guards/auth.guard.ts @@ -1,10 +1,5 @@ import { Injectable } from "@angular/core"; -import { - CanActivate, - ActivatedRouteSnapshot, - RouterStateSnapshot, - Router, -} from "@angular/router"; +import { CanActivate, Router } from "@angular/router"; import { Observable } from "rxjs"; import { TranslateService } from "@ngx-translate/core"; @@ -16,16 +11,17 @@ export class AuthGuard implements CanActivate { this.translateService = translate; } - canActivate( - next: ActivatedRouteSnapshot, - state: RouterStateSnapshot - ): Observable<boolean> | Promise<boolean> | boolean { + canActivate(): Observable<boolean> | Promise<boolean> | boolean { + // El usuario está logeado if (sessionStorage.getItem("currentUser")) { return true; } - this.router.navigate([ - "/" + this.translateService.get("i18n.code").value + "/login", - ]); + + // Se navega al login dependiendo del idioma + this.translateService + .get("i18n.code") + .subscribe((res) => this.router.navigate(["/" + res + "/login"])); + return false; } } diff --git a/Frontend Angular 4/src/app/shared/services/ghci.service.ts b/Frontend Angular 4/src/app/shared/services/ghci.service.ts index f3a7732f2ceb21edb35b12b30dd894e739aea360..2e07626375a29fe5312801d6918f18b9c7f726eb 100755 --- a/Frontend Angular 4/src/app/shared/services/ghci.service.ts +++ b/Frontend Angular 4/src/app/shared/services/ghci.service.ts @@ -108,11 +108,11 @@ export class GHCIService { console.log("Conexión con web socket exitosa"); }; this.connection.onclose = function (reason) { - //Codigo que indica la falta de permisos (sesion expirada por ejemplo) + // Codigo que indica la falta de permisos (sesion expirada por ejemplo) if (reason.code == 1008) { - this.router.navigate([ - "/" + this.translateService.get("i18n.code").value + "/login", - ]); + this.translateService + .get("i18n.code") + .subscribe((res) => this.router.navigate(["/" + res + "/login"])); } console.log("Conexión con web socket cerrada", reason); }.bind(this); diff --git a/Frontend Angular 4/src/app/shared/services/haskell.service.ts b/Frontend Angular 4/src/app/shared/services/haskell.service.ts index 690eab3f6772a9b397194db5881f4b2bc90454d7..292fbc999af7f11dc3e8c55678078016d8ad3361 100755 --- a/Frontend Angular 4/src/app/shared/services/haskell.service.ts +++ b/Frontend Angular 4/src/app/shared/services/haskell.service.ts @@ -161,9 +161,9 @@ export class HaskellService { */ private handleError(error: any) { if (error.status == 401) { - this.router.navigate([ - "/" + this.translateService.get("i18n.code").value + "/login", - ]); + this.translateService + .get("i18n.code") + .subscribe((res) => this.router.navigate(["/" + res + "/login"])); } // In a real world app, we might use a remote logging infrastructure // We'd also dig deeper into the error to get a better message diff --git a/Frontend Angular 4/src/app/shared/services/usuario.service.ts b/Frontend Angular 4/src/app/shared/services/usuario.service.ts index f470cb8bf45db2066bb654689bb98fd9e0a334af..b7ea17ef9afae6cafe754b76da0939b67893e389 100755 --- a/Frontend Angular 4/src/app/shared/services/usuario.service.ts +++ b/Frontend Angular 4/src/app/shared/services/usuario.service.ts @@ -47,9 +47,9 @@ export class UsuarioService { private handleError(error: any) { if (error.status == 401) { - this.router.navigate([ - "/" + this.translateService.get("i18n.code").value + "/login", - ]); + this.translateService + .get("i18n.code") + .subscribe((res) => this.router.navigate(["/" + res + "/login"])); } let errMsg = error.message ? error.message