Skip to content

Commit 358c22e

Browse files
mattjokeHejdaJakub
authored andcommitted
fix(admin): fix login screen service access component
* service-access login component no longer shows sidebar and header after logout * added logout notification so it is consistent with regular login
1 parent b7358c7 commit 358c22e

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

libs/perun/login/src/lib/login-screen-service-access/login-screen-service-access.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ <h2>{{'SHARED_LIB.PERUN.LOGIN_SERVICE_ACCESS.LABEL' | translate}}</h2>
55
<perun-web-apps-alert *ngIf="wrongUsernameOrPassword" alert_type="error">
66
{{'SHARED_LIB.PERUN.LOGIN_SERVICE_ACCESS.WRONG_LOGIN_OR_PASSWORD' | translate}}
77
</perun-web-apps-alert>
8+
<perun-web-apps-alert *ngIf="afterLogout" class="mb-2" alert_type="success">
9+
{{'SHARED_LIB.PERUN.LOGIN.LOGOUT_INFO' | translate}}
10+
</perun-web-apps-alert>
811
<mat-form-field appearance="outline" subscriptSizing="dynamic">
912
<mat-label>{{'SHARED_LIB.PERUN.LOGIN_SERVICE_ACCESS.USERNAME' | translate}}</mat-label>
1013
<input matInput required (keyup.enter)="startAuth()" [formControl]="usernameCtrl" />

libs/perun/login/src/lib/login-screen-service-access/login-screen-service-access.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
22
import { AuthzResolverService } from '@perun-web-apps/perun/openapi';
33
import { FormControl, Validators } from '@angular/forms';
44
import { Router } from '@angular/router';
5-
import { AuthService } from '@perun-web-apps/perun/services';
5+
import { AuthService, InitAuthService } from '@perun-web-apps/perun/services';
66

77
@Component({
88
selector: 'perun-web-apps-login-screen-service-access',
@@ -13,16 +13,18 @@ export class LoginScreenServiceAccessComponent implements OnInit {
1313
usernameCtrl = new FormControl<string>(null, [Validators.required]);
1414
passwordCtrl = new FormControl<string>(null, [Validators.required]);
1515
wrongUsernameOrPassword = false;
16+
afterLogout: boolean;
1617

1718
constructor(
1819
private authzService: AuthzResolverService,
1920
private auth: AuthService,
21+
private initAuth: InitAuthService,
2022
private router: Router
2123
) {}
2224

2325
startAuth(): void {
2426
if (this.usernameCtrl.invalid || this.passwordCtrl.invalid) return;
25-
27+
sessionStorage.removeItem('baAfterLogout');
2628
sessionStorage.setItem('basicUsername', this.usernameCtrl.value);
2729
sessionStorage.setItem('basicPassword', this.passwordCtrl.value);
2830
this.authzService.getPerunPrincipal().subscribe({
@@ -38,7 +40,18 @@ export class LoginScreenServiceAccessComponent implements OnInit {
3840

3941
ngOnInit(): void {
4042
if (this.auth.isLoggedIn() || sessionStorage.getItem('baPrincipal')) {
43+
sessionStorage.removeItem('baAfterLogout');
4144
void this.router.navigate([''], { queryParamsHandling: 'merge' });
4245
}
46+
47+
if (sessionStorage.getItem('baLogout')) {
48+
this.initAuth.invalidateServiceAccess();
49+
location.reload();
50+
}
51+
52+
if (sessionStorage.getItem('baAfterLogout')) {
53+
this.afterLogout = true;
54+
sessionStorage.setItem('baAfterLogout', 'false');
55+
}
4356
}
4457
}

libs/perun/services/src/lib/auth.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class AuthService {
4545
sessionStorage.removeItem('basicUsername');
4646
sessionStorage.removeItem('basicPassword');
4747
sessionStorage.setItem('baLogout', 'true');
48+
sessionStorage.setItem('baAfterLogout', 'true');
4849
void this.router.navigate(['/service-access'], { queryParamsHandling: 'preserve' });
4950
} else {
5051
this.logoutProcess = true;

libs/perun/services/src/lib/init-auth.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getDefaultDialogConfig } from '@perun-web-apps/perun/utils';
1010
import { Params, Router } from '@angular/router';
1111
import { OAuthInfoEvent, OAuthService } from 'angular-oauth2-oidc';
1212
import { filter } from 'rxjs/operators';
13-
import { firstValueFrom } from 'rxjs';
13+
import { firstValueFrom, timer } from 'rxjs';
1414
import { MfaHandlerService } from './mfa-handler.service';
1515

1616
@Injectable({
@@ -190,6 +190,14 @@ export class InitAuthService {
190190
}
191191
}
192192

193+
invalidateServiceAccess(): void {
194+
// Has to be promise, bc. of ExpressionChangedAfterItHasBeenCheckedError
195+
timer(0).subscribe(() => {
196+
this.serviceAccess = false;
197+
this.setLoginScreen(true);
198+
});
199+
}
200+
193201
private setLoginScreen(shown: boolean): void {
194202
this.loginScreenShown = shown;
195203
}

0 commit comments

Comments
 (0)