diff --git a/set-env.ts b/set-env.ts index 52e1fa0..e9b558b 100644 --- a/set-env.ts +++ b/set-env.ts @@ -13,7 +13,7 @@ const environmentVars = `import {NgxLoggerLevel} from 'ngx-logger'; export const environment = { production: ${isProduction}, bloxbergChainId: ${process.env.CIC_CHAIN_ID || 8996}, - level: ${process.env.LOG_LEVEL || 'NgxLoggerLevel.OFF'}, + level: ${process.env.LOG_LEVEL || 'NgxLoggerLevel.ERROR'}, serverLogLevel: ${process.env.SERVER_LOG_LEVEL || 'NgxLoggerLevel.OFF'}, loggingUrl: '${process.env.CIC_LOGGING_URL || 'http://localhost:8000'}', cicMetaUrl: '${process.env.CIC_META_URL || 'https://meta.dev.grassrootseconomics.net'}', diff --git a/src/app/_interceptors/error.interceptor.ts b/src/app/_interceptors/error.interceptor.ts index a0fe704..a88ce5c 100644 --- a/src/app/_interceptors/error.interceptor.ts +++ b/src/app/_interceptors/error.interceptor.ts @@ -34,12 +34,12 @@ export class ErrorInterceptor implements HttpInterceptor { errorMessage = `Backend returned code ${err.status}, body was: ${JSON.stringify(err.error)}`; this.loggingService.sendErrorLevelMessage(errorMessage, this, {error: err}); } - if (isDevMode()) { - this.errorDialogService.openDialog({ - message: errorMessage || err.error.message || err.statusText || 'Unknown Error', - status: err.status || 0 - }); - } + // if (isDevMode()) { + // this.errorDialogService.openDialog({ + // message: errorMessage || err.error.message || err.statusText || 'Unknown Error', + // status: err.status || 0 + // }); + // } switch (err.status) { case 401: // unauthorized this.router.navigateByUrl('/auth').then(); diff --git a/src/app/_interceptors/http-config.interceptor.ts b/src/app/_interceptors/http-config.interceptor.ts index d10de43..e03d0db 100644 --- a/src/app/_interceptors/http-config.interceptor.ts +++ b/src/app/_interceptors/http-config.interceptor.ts @@ -23,7 +23,7 @@ export class HttpConfigInterceptor implements HttpInterceptor { // if (!request.headers.has('Content-Type')) { // request = request.clone({headers: request.headers.set('Content-Type', 'application/json')}); // } - + // request = request.clone({headers: request.headers.set('Accept', 'application/json')}); return next.handle(request); } diff --git a/src/app/_pgp/pgp-key-store.ts b/src/app/_pgp/pgp-key-store.ts index ed3938c..f1b1e22 100644 --- a/src/app/_pgp/pgp-key-store.ts +++ b/src/app/_pgp/pgp-key-store.ts @@ -1,6 +1,7 @@ import { KeyStore } from 'cic-client-meta'; // const openpgp = require('openpgp'); //TODO should we put this on the mutalble key store object import * as openpgp from 'openpgp'; +import {throwError} from 'rxjs'; const keyring = new openpgp.Keyring(); interface MutableKeyStore extends KeyStore { @@ -83,6 +84,7 @@ class MutablePgpKeyStore implements MutableKeyStore{ } getFingerprint(): string { + // TODO Handle multiple keys return keyring.privateKeys.keys[0].keyPacket.fingerprint; } diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index 72f5686..086127c 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -8,6 +8,7 @@ import {ErrorDialogService} from '@app/_services/error-dialog.service'; import {tap} from 'rxjs/operators'; import { HttpClient } from '@angular/common/http'; import {Observable } from 'rxjs'; +import * as openpgp from 'openpgp'; @Injectable({ providedIn: 'root' @@ -109,8 +110,12 @@ export class AuthService { async loginResponse(o): Promise { - const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore); - this.sendResponse(r); + try { + const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore); + this.sendResponse(r); + } catch (error) { + this.errorDialogService.openDialog({message: 'Incorrect key passphrase.'}); + } } loginView(): void { @@ -120,8 +125,10 @@ export class AuthService { } async setKey(privateKeyArmored): Promise { + // TODO Check if key is encrypted else warn user. + try { - const isValidKeyCheck = await this.mutableKeyStore.isValidKey(privateKeyArmored) + const isValidKeyCheck = await this.mutableKeyStore.isValidKey(privateKeyArmored); if (!isValidKeyCheck) { throw Error('The private key is invalid'); } @@ -154,7 +161,10 @@ export class AuthService { return this.httpClient.get(`${environment.publicKeysUrl}`, {responseType: 'text'}) .pipe(tap( data => { }, - error => { this.loggingService.sendErrorLevelMessage('Unable to load trusted public keys.', this, {error}); } + error => { + this.loggingService.sendErrorLevelMessage('Unable to load trusted public keys.', this, {error}); + this.errorDialogService.openDialog({message: 'Trusted keys endpoint can\'t be reached. Please try again later.'}); + } )); } diff --git a/src/app/_services/error-dialog.service.ts b/src/app/_services/error-dialog.service.ts index 9560674..37db8cd 100644 --- a/src/app/_services/error-dialog.service.ts +++ b/src/app/_services/error-dialog.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import {MatDialog} from '@angular/material/dialog'; import {ErrorDialogComponent} from '@app/shared/error-dialog/error-dialog.component'; -import {LoggingService} from '@app/_services/logging.service'; @Injectable({ providedIn: 'root' @@ -11,7 +10,6 @@ export class ErrorDialogService { constructor( public dialog: MatDialog, - private loggingService: LoggingService ) { } openDialog(data): any { @@ -24,10 +22,6 @@ export class ErrorDialogService { data }); - dialogRef.afterClosed().subscribe(result => { - this.loggingService.sendInfoLevelMessage('The dialog was closed'); - this.isDialogOpen = false; - const res = result; - }); + dialogRef.afterClosed().subscribe(() => this.isDialogOpen = false); } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index aaaa976..882bc78 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -21,6 +21,7 @@ export class AppComponent { ) { (async () => { await this.authService.mutableKeyStore.loadKeyring(); + // TODO Handle error from get public keys function. this.authService.getPublicKeys().subscribe(this.authService.mutableKeyStore.importPublicKey); // this.loggingService.sendInfoLevelMessage(await this.tokenService.getTokens()); })(); diff --git a/src/app/shared/error-dialog/error-dialog.component.html b/src/app/shared/error-dialog/error-dialog.component.html index ec0825c..f508467 100644 --- a/src/app/shared/error-dialog/error-dialog.component.html +++ b/src/app/shared/error-dialog/error-dialog.component.html @@ -3,8 +3,8 @@

Message: {{ data.message }}

-

- Status: {{ data.status }} +

+ Status: {{ data?.status }}