Refactor get challenge method.
This commit is contained in:
parent
a9ad7012d8
commit
ad3767017b
@ -71,19 +71,19 @@ export class AuthService {
|
|||||||
}).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error}));
|
}).catch(error => this.loggingService.sendErrorLevelMessage('Login rejected', this, {error}));
|
||||||
}
|
}
|
||||||
|
|
||||||
getChallenge(password: string): void {
|
async getChallenge(): Promise<any> {
|
||||||
fetch(environment.cicMetaUrl).then(async response => {
|
return fetch(environment.cicMetaUrl).then(async response => {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
const authHeader = response.headers.get('WWW-Authenticate');
|
const authHeader = response.headers.get('WWW-Authenticate');
|
||||||
const o = hobaParseChallengeHeader(authHeader);
|
return hobaParseChallengeHeader(authHeader);
|
||||||
await this.loginResponse(o, password);
|
|
||||||
}
|
}
|
||||||
}).catch(error => this.loggingService.sendErrorLevelMessage('Fetching challenge failed', this, {error}));
|
}).catch(error => this.loggingService.sendErrorLevelMessage('Fetching challenge failed', this, {error}));
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordLogin(password: string): boolean {
|
async passwordLogin(password: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
this.getChallenge(password);
|
const o = await this.getChallenge();
|
||||||
|
await this.loginResponse(o, password);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e});
|
this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e});
|
||||||
|
@ -39,7 +39,6 @@ export class AuthComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
if (setKey && this.authService.sessionToken !== undefined) {
|
if (setKey && this.authService.sessionToken !== undefined) {
|
||||||
this.loginView();
|
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);
|
const keySetup = await this.authService.setKey(this.keyFormStub.key.value);
|
||||||
if (keySetup) {
|
if (keySetup) {
|
||||||
this.passwordInput();
|
this.passwordInput();
|
||||||
this.setPasswordState('Enter Password to log in with PGP key ' + this.authService.mutableKeyStore.getPrivateKeyId());
|
|
||||||
}
|
}
|
||||||
this.keyFormLoading = false;
|
this.keyFormLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onPasswordInput(): void {
|
async onPasswordInput(): Promise<void> {
|
||||||
this.passwordFormSubmitted = true;
|
this.passwordFormSubmitted = true;
|
||||||
|
|
||||||
if (this.passwordForm.invalid) { return; }
|
if (this.passwordForm.invalid) { return; }
|
||||||
|
|
||||||
this.passwordFormLoading = true;
|
this.passwordFormLoading = true;
|
||||||
const passwordLogin = this.authService.passwordLogin(this.passwordFormStub.password.value);
|
const passwordLogin = await this.authService.passwordLogin(this.passwordFormStub.password.value);
|
||||||
if (passwordLogin) {
|
if (passwordLogin) {
|
||||||
this.loginView();
|
this.loginView();
|
||||||
}
|
}
|
||||||
@ -90,12 +88,14 @@ export class AuthComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
passwordInput(): void {
|
passwordInput(): void {
|
||||||
// this.authService.sessionToken = undefined;
|
this.authService.sessionToken = undefined;
|
||||||
this.switchWindows(false, true, false);
|
this.switchWindows(false, true, false);
|
||||||
|
this.setPasswordState('Enter Password to log in with PGP key ' + this.authService.mutableKeyStore.getPrivateKeyId());
|
||||||
}
|
}
|
||||||
|
|
||||||
loginView(): void {
|
loginView(): void {
|
||||||
this.switchWindows(false, false, true);
|
this.switchWindows(false, false, true);
|
||||||
|
this.authService.setState('Click button to log in');
|
||||||
}
|
}
|
||||||
|
|
||||||
switchWindows(divOneStatus: boolean, divTwoStatus: boolean, divThreeStatus: boolean): void {
|
switchWindows(divOneStatus: boolean, divTwoStatus: boolean, divThreeStatus: boolean): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user