Refactor get challenge method.

This commit is contained in:
Spencer Ofwiti 2021-04-19 15:22:44 +03:00
parent a9ad7012d8
commit ad3767017b
2 changed files with 11 additions and 11 deletions

View File

@ -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<any> {
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<boolean> {
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});

View File

@ -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<void> {
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 {