diff --git a/src/app/app-root/code-input/code-input.component.ts b/src/app/app-root/code-input/code-input.component.ts index 87c9ee334cd0e46c24dccc55ffff5342e30c523d..cfc31613fa62a0baf7101c36ac56ce35de9f2db6 100644 --- a/src/app/app-root/code-input/code-input.component.ts +++ b/src/app/app-root/code-input/code-input.component.ts @@ -62,12 +62,7 @@ export class CodeInputComponent implements OnInit{ } } else { const authDataTyped = authData as AuthData; - if (authDataTyped.customTexts) { - this.cts.addCustomTexts(authDataTyped.customTexts); - } this.mds.setAuthData(authDataTyped); - - // let the app-root routing guard decide where to go to this.router.navigate(['/r']); } }) diff --git a/src/app/app-root/login/login.component.ts b/src/app/app-root/login/login.component.ts index a17fc55f88cccd49f546afdcebe465659458831d..b959ea85ad5c6fc41ebba8676128950a75c5541c 100644 --- a/src/app/app-root/login/login.component.ts +++ b/src/app/app-root/login/login.component.ts @@ -55,15 +55,11 @@ export class LoginComponent implements OnInit, OnDestroy { } } else { const authDataTyped = authData as AuthData; - if (authDataTyped.customTexts) { - this.cts.addCustomTexts(authDataTyped.customTexts); - } this.mds.setAuthData(authDataTyped); if (this.returnTo) { this.router.navigateByUrl(this.returnTo); } else { - // let the app-root routing guard decide where to go to this.router.navigate(['/r']); } } diff --git a/src/app/app-root/route-dispatcher/route-dispatcher.component.html b/src/app/app-root/route-dispatcher/route-dispatcher.component.html index bc9ae6065218cb9f74d4aa999a86eaaeffc25763..91080f80d45547b7345c7dc3fc817bcdd6a60c10 100644 --- a/src/app/app-root/route-dispatcher/route-dispatcher.component.html +++ b/src/app/app-root/route-dispatcher/route-dispatcher.component.html @@ -6,6 +6,10 @@ {{url}} </div> </mat-card-content> + + <mat-card-actions> + <button [routerLink]="['/']" mat-raised-button color="primary">Zur Startseite</button> + </mat-card-actions> </mat-card> <app-status-card></app-status-card> diff --git a/src/app/app-routing-guards.ts b/src/app/app-routing-guards.ts index 01e2b475a5d9d7500c3f6b4e06d4806807f5ac36..99cf69a2456ffbdb76e640cb98368f959487b4e0 100644 --- a/src/app/app-routing-guards.ts +++ b/src/app/app-routing-guards.ts @@ -2,12 +2,12 @@ import {Injectable} from "@angular/core"; import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from "@angular/router"; import {MainDataService} from "./maindata.service"; import {Observable} from "rxjs"; -import {AuthAccessKeyType, AuthFlagType} from "./app.interfaces"; +import {AuthAccessKeyType, AuthData, AuthFlagType} from "./app.interfaces"; +import {BackendService} from "./backend.service"; @Injectable() export class RouteDispatcherActivateGuard implements CanActivate { constructor( - private mds: MainDataService, private router: Router ) { } @@ -39,3 +39,32 @@ export class RouteDispatcherActivateGuard implements CanActivate { } } +@Injectable() +export class DirectLoginActivateGuard implements CanActivate { + constructor( + private mds: MainDataService, + private bs: BackendService, + private router: Router + ) { + } + + canActivate( + next: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { + + const authData = MainDataService.getAuthDataFromLocalStorage(); + if (!authData) { + const directLoginName = state.url.substr(1); + if (directLoginName.length > 0 && directLoginName.indexOf('/') < 0) { + this.bs.nameOnlyLogin(directLoginName).subscribe(authData => { + if (typeof authData !== 'number') { + this.mds.setAuthData(authData as AuthData); + this.router.navigate(['/r']); + } + }) + } + } + return true + } +} + diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index f23539104ce5b420d570beaaf62c3aae26ee0f6e..fa4eda5484805c76b8288ee88a8d73a2af22c5b2 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -6,7 +6,7 @@ import {LoginComponent} from "./app-root/login/login.component"; import {SysCheckStarterComponent} from "./app-root/sys-check-starter/sys-check-starter.component"; import {AdminStarterComponent} from "./app-root/admin-starter/admin-starter.component"; import {CodeInputComponent} from "./app-root/code-input/code-input.component"; -import {RouteDispatcherActivateGuard} from "./app-routing-guards"; +import {DirectLoginActivateGuard, RouteDispatcherActivateGuard} from "./app-routing-guards"; import {TestStarterComponent} from "./app-root/test-starter/test-starter.component"; import {RouteDispatcherComponent} from "./app-root/route-dispatcher/route-dispatcher.component"; @@ -36,12 +36,12 @@ const routes: Routes = [ {path: 'superadmin', loadChildren: () => import('./superadmin/superadmin.module').then(m => m.SuperadminModule)}, {path: 'wsmonitor', loadChildren: () => import('./workspace-monitor/workspace-monitor.module').then(m => m.WorkspaceMonitorModule)}, {path: 't', loadChildren: () => import('./test-controller/test-controller.module').then(m => m.TestControllerModule)}, - {path: '**', component: RouteDispatcherComponent} + {path: '**', component: RouteDispatcherComponent, canActivate: [DirectLoginActivateGuard]} ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule], - providers: [RouteDispatcherActivateGuard] + providers: [RouteDispatcherActivateGuard, DirectLoginActivateGuard] }) export class AppRoutingModule { } diff --git a/src/app/backend.service.ts b/src/app/backend.service.ts index 1de59afbf437ca9cea1c2a5068b361f35958ff6b..2770c29311682ff1879ed85585cd35e5211973cc 100644 --- a/src/app/backend.service.ts +++ b/src/app/backend.service.ts @@ -28,7 +28,8 @@ export class BackendService { login(name: string, password: string): Observable<AuthData | number> { - return this.http + if (password) { + return this.http .put<AuthData>(this.serverUrl + 'session/admin', {name, password}) .pipe( catchError(errCode => of(errCode)), @@ -47,6 +48,17 @@ export class BackendService { } }) ); + } else { + return this.nameOnlyLogin(name); + } + } + + nameOnlyLogin(name: string): Observable<AuthData | number> { + return this.http + .put<AuthData>(this.serverUrl + 'session/login', {name}) + .pipe( + catchError(errCode => of(errCode)) + ); } codeLogin(code: string): Observable<AuthData | number> { diff --git a/src/app/maindata.service.ts b/src/app/maindata.service.ts index 5dcc09b08f7e4eb7df137c3b3f7b610a478460c1..7890b505facb001fe2b460e918b917c89d0605c1 100644 --- a/src/app/maindata.service.ts +++ b/src/app/maindata.service.ts @@ -58,6 +58,10 @@ export class MainDataService { setAuthData(authData: AuthData = null) { if (authData) { + if (authData.customTexts) { + this.cts.addCustomTexts(authData.customTexts); + authData.customTexts = null; + } MainDataService.setAuthDataToLocalStorage(authData); } else { MainDataService.setAuthDataToLocalStorage();