Add user logout.

This commit is contained in:
Spencer Ofwiti 2021-03-24 19:41:11 +03:00
parent f115b5dae6
commit 25fd616ff7
4 changed files with 9 additions and 5 deletions

View File

@ -47,7 +47,7 @@ export class AuthService {
throw new Error('login rejected'); throw new Error('login rejected');
} }
this.sessionLoginCount++; this.sessionLoginCount++;
this.setState('Click button to perform login ' + this.sessionLoginCount + ' with token ' + this.sessionToken); this.setState('Click button to log in');
return; return;
}); });
xhr.send(); xhr.send();
@ -67,7 +67,7 @@ export class AuthService {
this.sessionToken = xhr.getResponseHeader('Token'); this.sessionToken = xhr.getResponseHeader('Token');
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken); sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken);
this.sessionLoginCount++; this.sessionLoginCount++;
this.setState('Click button to perform login ' + this.sessionLoginCount + ' with token ' + this.sessionToken); this.setState('Click button to log in');
return; return;
}); });
xhr.send(); xhr.send();
@ -147,6 +147,7 @@ export class AuthService {
logout(): void { logout(): void {
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN')); sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
this.sessionToken = undefined;
window.location.reload(true); window.location.reload(true);
} }

View File

@ -29,8 +29,7 @@ export class AuthComponent implements OnInit {
if (this.authService.privateKey !== undefined) { if (this.authService.privateKey !== undefined) {
const setKey = await this.authService.setKey(this.authService.privateKey); const setKey = await this.authService.setKey(this.authService.privateKey);
if (setKey && this.authService.sessionToken !== undefined) { if (setKey && this.authService.sessionToken !== undefined) {
this.authService.setState( this.authService.setState('Click button to log in');
'Click button to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken);
} }
} }
} }

View File

@ -50,7 +50,7 @@
</div> </div>
<hr> <hr>
<div class="card-body"> <div class="card-body">
<button mat-raised-button color="primary" type="button" class="btn btn-outline-primary"> LOGOUT ADMIN </button> <button mat-raised-button color="primary" type="button" class="btn btn-outline-primary" (click)="logout()"> LOGOUT ADMIN </button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -41,4 +41,8 @@ export class SettingsComponent implements OnInit {
downloadCsv(): void { downloadCsv(): void {
exportCsv(this.trustedUsers, 'users'); exportCsv(this.trustedUsers, 'users');
} }
logout(): void {
this.authService.logout();
}
} }