diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index 9c08f5a..6cdac36 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -71,19 +71,19 @@ export class AuthService { }).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error})); } - getChallenge(password: string): void { - fetch(environment.cicMetaUrl).then(async response => { + async getChallenge(): Promise { + return fetch(environment.cicMetaUrl).then(async response => { if (response.status === 401) { const authHeader = response.headers.get('WWW-Authenticate'); - const o = hobaParseChallengeHeader(authHeader); - await this.loginResponse(o, password); + return hobaParseChallengeHeader(authHeader); } }).catch(error => this.loggingService.sendErrorLevelMessage('Fetching challenge failed', this, {error})); } - passwordLogin(password: string): boolean { + async passwordLogin(password: string): Promise { try { - this.getChallenge(password); + const o = await this.getChallenge(); + await this.loginResponse(o, password); return true; } catch (e) { this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e}); diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index 081f6c1..2bf7c89 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -39,7 +39,6 @@ export class AuthComponent implements OnInit { } if (setKey && this.authService.sessionToken !== undefined) { this.loginView(); - this.authService.setState('Click button to log in'); } } } @@ -56,18 +55,17 @@ export class AuthComponent implements OnInit { const keySetup = await this.authService.setKey(this.keyFormStub.key.value); if (keySetup) { this.passwordInput(); - this.setPasswordState('Enter Password to log in with PGP key ' + this.authService.mutableKeyStore.getPrivateKeyId()); } this.keyFormLoading = false; } - onPasswordInput(): void { + async onPasswordInput(): Promise { this.passwordFormSubmitted = true; if (this.passwordForm.invalid) { return; } this.passwordFormLoading = true; - const passwordLogin = this.authService.passwordLogin(this.passwordFormStub.password.value); + const passwordLogin = await this.authService.passwordLogin(this.passwordFormStub.password.value); if (passwordLogin) { this.loginView(); } @@ -90,12 +88,14 @@ export class AuthComponent implements OnInit { } passwordInput(): void { - // this.authService.sessionToken = undefined; + this.authService.sessionToken = undefined; this.switchWindows(false, true, false); + this.setPasswordState('Enter Password to log in with PGP key ' + this.authService.mutableKeyStore.getPrivateKeyId()); } loginView(): void { this.switchWindows(false, false, true); + this.authService.setState('Click button to log in'); } switchWindows(divOneStatus: boolean, divTwoStatus: boolean, divThreeStatus: boolean): void {