Lint code.

This commit is contained in:
Spencer Ofwiti 2021-06-30 19:20:47 +03:00
parent 0a2c088036
commit 28fc0048f7
3 changed files with 30 additions and 25 deletions

View File

@ -14,7 +14,7 @@ import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
// Application imports
import { LoggingService } from '@app/_services';
import { ErrorDialogService, LoggingService } from '@app/_services';
/** Intercepts and handles errors from outgoing HTTP request. */
@Injectable()
@ -22,10 +22,15 @@ export class ErrorInterceptor implements HttpInterceptor {
/**
* Initialization of the error interceptor.
*
* @param errorDialogService - A service that provides a dialog box for displaying errors to the user.
* @param loggingService - A service that provides logging capabilities.
* @param router - A service that provides navigation among views and URL manipulation capabilities.
*/
constructor(private loggingService: LoggingService, private router: Router) {}
constructor(
private errorDialogService: ErrorDialogService,
private loggingService: LoggingService,
private router: Router
) {}
/**
* Intercepts HTTP requests.
@ -54,9 +59,10 @@ export class ErrorInterceptor implements HttpInterceptor {
this.router.navigateByUrl('/auth').then();
break;
case 403: // forbidden
this.errorDialogService.openDialog(
{ message: 'Access to resource is not allowed (Error 403)'})
//alert('Access to resource is not allowed!');
this.errorDialogService.openDialog({
message: 'Access to resource is not allowed (Error 403)',
});
// alert('Access to resource is not allowed!');
break;
}
// Return an observable with a user-facing error message.

View File

@ -46,7 +46,7 @@ export class AuthService {
}
getWithToken(): Promise<boolean> {
const sessionToken = this.getSessionToken()
const sessionToken = this.getSessionToken();
const headers = {
Authorization: 'Bearer ' + sessionToken,
'Content-Type': 'application/json;charset=utf-8',
@ -92,33 +92,32 @@ export class AuthService {
async login(): Promise<boolean> {
if (this.getSessionToken()) {
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
}
}
const o = await this.getChallenge();
const r = await signChallenge(
o.challenge,
o.realm,
environment.cicMetaUrl,
this.mutableKeyStore
o.challenge,
o.realm,
environment.cicMetaUrl,
this.mutableKeyStore
);
const tokenResponse = await this.sendSignedChallenge(r)
.then((response) => {
const token = response.headers.get('Token');
if (token) {
return token;
}
if (response.status === 401) {
throw new HttpError('You are not authorized to use this system', response.status);
}
if (!response.ok) {
throw new HttpError('Unknown error from authentication server', response.status);
}
const tokenResponse = await this.sendSignedChallenge(r).then((response) => {
const token = response.headers.get('Token');
if (token) {
return token;
}
if (response.status === 401) {
throw new HttpError('You are not authorized to use this system', response.status);
}
if (!response.ok) {
throw new HttpError('Unknown error from authentication server', response.status);
}
});
if (tokenResponse) {
this.setSessionToken(tokenResponse);
//this.setState('Click button to log in');
// this.setState('Click button to log in');
return true;
}
return false;

View File

@ -57,7 +57,7 @@ export class AuthComponent implements OnInit {
}
} catch (HttpError) {
this.errorDialogService.openDialog({
message: "Failed to login please try again.",
message: 'Failed to login please try again.',
});
}
}