Format files using linter.

This commit is contained in:
Spencer Ofwiti 2021-06-11 09:26:50 +03:00
parent df395b7b61
commit 0866c4c22f
5 changed files with 96 additions and 101 deletions

View File

@ -9,7 +9,7 @@ export class HttpConfigInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
// const token: string = sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN')); // const token: string = sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
const token: string = AuthService.getSessionToken() const token: string = AuthService.getSessionToken();
if (token) { if (token) {
request = request.clone({ headers: request.headers.set('Authorization', 'Bearer ' + token) }); request = request.clone({ headers: request.headers.set('Authorization', 'Bearer ' + token) });

View File

@ -14,13 +14,6 @@ import { BehaviorSubject, Observable } from 'rxjs';
providedIn: 'root', providedIn: 'root',
}) })
export class AuthService { export class AuthService {
mutableKeyStore: MutableKeyStore;
trustedUsers: Array<Staff> = [];
private trustedUsersList: BehaviorSubject<Array<Staff>> = new BehaviorSubject<Array<Staff>>(
this.trustedUsers
);
trustedUsersSubject: Observable<Array<Staff>> = this.trustedUsersList.asObservable();
constructor( constructor(
private httpClient: HttpClient, private httpClient: HttpClient,
private loggingService: LoggingService, private loggingService: LoggingService,
@ -28,6 +21,16 @@ export class AuthService {
) { ) {
this.mutableKeyStore = new MutablePgpKeyStore(); this.mutableKeyStore = new MutablePgpKeyStore();
} }
mutableKeyStore: MutableKeyStore;
trustedUsers: Array<Staff> = [];
private trustedUsersList: BehaviorSubject<Array<Staff>> = new BehaviorSubject<Array<Staff>>(
this.trustedUsers
);
trustedUsersSubject: Observable<Array<Staff>> = this.trustedUsersList.asObservable();
public static getSessionToken(): string {
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
}
async init(): Promise<void> { async init(): Promise<void> {
await this.mutableKeyStore.loadKeyring(); await this.mutableKeyStore.loadKeyring();
@ -36,10 +39,6 @@ export class AuthService {
} }
} }
public static getSessionToken(): string {
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
}
setSessionToken(token): void { setSessionToken(token): void {
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), token); sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), token);
} }
@ -59,9 +58,9 @@ export class AuthService {
}; };
return fetch(environment.cicMetaUrl, options).then((response) => { return fetch(environment.cicMetaUrl, options).then((response) => {
if (!response.ok) { if (!response.ok) {
this.loggingService.sendErrorLevelMessage('failed to get with auth token.', this.loggingService.sendErrorLevelMessage('failed to get with auth token.', this, {
this, error: '',
{ error: "" }); });
return false; return false;
} }
@ -79,12 +78,11 @@ export class AuthService {
const options = { const options = {
headers, headers,
}; };
return fetch(environment.cicMetaUrl, options) return fetch(environment.cicMetaUrl, options);
} }
getChallenge(): Promise<any> { getChallenge(): Promise<any> {
return fetch(environment.cicMetaUrl) return fetch(environment.cicMetaUrl).then((response) => {
.then(response => {
if (response.status === 401) { if (response.status === 401) {
const authHeader: string = response.headers.get('WWW-Authenticate'); const authHeader: string = response.headers.get('WWW-Authenticate');
return hobaParseChallengeHeader(authHeader); return hobaParseChallengeHeader(authHeader);
@ -105,29 +103,25 @@ export class AuthService {
this.mutableKeyStore this.mutableKeyStore
); );
const tokenResponse = await this.sendSignedChallenge(r) const tokenResponse = await this.sendSignedChallenge(r).then((response) => {
.then(response => { const token = response.headers.get('Token');
const token = response.headers.get('Token')
if (token) { if (token) {
return token return token;
} }
if (response.status === 401) { if (response.status === 401) {
let e = new HttpError("You are not authorized to use this system", response.status) throw new HttpError('You are not authorized to use this system', response.status);
throw e
} }
if (!response.ok) { if (!response.ok) {
let e = new HttpError("Unknown error from authentication server", response.status) throw new HttpError('Unknown error from authentication server', response.status);
throw e
} }
}) });
if (tokenResponse) { if (tokenResponse) {
this.setSessionToken(tokenResponse); this.setSessionToken(tokenResponse);
this.setState('Click button to log in'); this.setState('Click button to log in');
return true return true;
} }
return false return false;
} }
loginView(): void { loginView(): void {

View File

@ -5,10 +5,9 @@ import { TokenRegistry } from '@app/_eth';
import { HttpGetter } from '@app/_helpers'; import { HttpGetter } from '@app/_helpers';
import { Web3Service } from '@app/_services/web3.service'; import { Web3Service } from '@app/_services/web3.service';
// export interface RegistryCollection { // export interface RegistryCollection {
// cicRegistry: CICRegistry, // cicRegistry: CICRegistry;
// tokenRegistry: TokenRegistry // tokenRegistry: TokenRegistry;
// } // }
@Injectable({ @Injectable({
@ -30,8 +29,7 @@ export class RegistryService {
['../../assets/js/block-sync/data'] ['../../assets/js/block-sync/data']
); );
RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
await RegistryService.registry.load() await RegistryService.registry.load();
} }
return RegistryService.registry; return RegistryService.registry;
} }
@ -39,16 +37,17 @@ export class RegistryService {
public static async getTokenRegistry(): Promise<TokenRegistry> { public static async getTokenRegistry(): Promise<TokenRegistry> {
if (!RegistryService.tokenRegistry) { if (!RegistryService.tokenRegistry) {
// then initial it // then initial it
const registry = await RegistryService.getRegistry() const registry = await RegistryService.getRegistry();
const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry') const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName(
'TokenRegistry'
);
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress); RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(RegistryService.tokenRegistry) resolve(RegistryService.tokenRegistry);
}) });
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(RegistryService.tokenRegistry); resolve(RegistryService.tokenRegistry);
}) });
} }
} }

View File

@ -14,7 +14,9 @@ export class TokenService {
tokenRegistry: TokenRegistry; tokenRegistry: TokenRegistry;
onload: (status: boolean) => void; onload: (status: boolean) => void;
tokens: Array<Token> = []; tokens: Array<Token> = [];
private tokensList: BehaviorSubject<Array<Token>> = new BehaviorSubject<Array<Token>>(this.tokens); private tokensList: BehaviorSubject<Array<Token>> = new BehaviorSubject<Array<Token>>(
this.tokens
);
tokensSubject: Observable<Array<Token>> = this.tokensList.asObservable(); tokensSubject: Observable<Array<Token>> = this.tokensList.asObservable();
constructor(private httpClient: HttpClient) {} constructor(private httpClient: HttpClient) {}

View File

@ -22,7 +22,7 @@ export class AuthComponent implements OnInit {
private authService: AuthService, private authService: AuthService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private errorDialogService: ErrorDialogService, private errorDialogService: ErrorDialogService
) {} ) {}
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
@ -49,7 +49,7 @@ export class AuthComponent implements OnInit {
async login(): Promise<void> { async login(): Promise<void> {
try { try {
const loginResult = await this.authService.login() const loginResult = await this.authService.login();
if (loginResult) { if (loginResult) {
this.router.navigate(['/home']); this.router.navigate(['/home']);
} }