From 20794381f185f01d7c3e31026f3fdcec44fbc90f Mon Sep 17 00:00:00 2001 From: Julius Gruber Date: Wed, 5 Jun 2019 13:39:18 +0200 Subject: [PATCH] Refactoring of auth.interceptor --- src/app/app.module.ts | 1 + src/app/core/auth/auth-request.service.ts | 30 +++++++++++---------- src/app/core/auth/auth.interceptor.ts | 8 +++--- src/app/shared/log-in/log-in.component.html | 3 +++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ce5a2d78a2..ddcd78ce8e 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -76,6 +76,7 @@ const ENTITY_IMPORTS = [ IMPORTS.push( StoreDevtoolsModule.instrument({ maxAge: 100, + // logOnly: false, logOnly: ENV_CONFIG.production, }) ); diff --git a/src/app/core/auth/auth-request.service.ts b/src/app/core/auth/auth-request.service.ts index 726bd0c44b..7b2620bf13 100644 --- a/src/app/core/auth/auth-request.service.ts +++ b/src/app/core/auth/auth-request.service.ts @@ -1,15 +1,15 @@ -import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; -import { distinctUntilChanged, filter, map, mergeMap, tap } from 'rxjs/operators'; -import { Inject, Injectable } from '@angular/core'; -import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { RequestService } from '../data/request.service'; -import { GLOBAL_CONFIG } from '../../../config'; -import { GlobalConfig } from '../../../config/global-config.interface'; -import { isNotEmpty } from '../../shared/empty.util'; -import { AuthGetRequest, AuthPostRequest, GetRequest, PostRequest, RestRequest } from '../data/request.models'; -import { AuthStatusResponse, ErrorResponse } from '../cache/response.models'; -import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; -import { getResponseFromEntry } from '../shared/operators'; +import {Observable, of as observableOf, throwError as observableThrowError} from 'rxjs'; +import {distinctUntilChanged, filter, map, mergeMap, tap} from 'rxjs/operators'; +import {Inject, Injectable} from '@angular/core'; +import {HALEndpointService} from '../shared/hal-endpoint.service'; +import {RequestService} from '../data/request.service'; +import {GLOBAL_CONFIG} from '../../../config'; +import {GlobalConfig} from '../../../config/global-config.interface'; +import {isNotEmpty} from '../../shared/empty.util'; +import {AuthGetRequest, AuthPostRequest, GetRequest, PostRequest, RestRequest} from '../data/request.models'; +import {AuthStatusResponse, ErrorResponse} from '../cache/response.models'; +import {HttpOptions} from '../dspace-rest-v2/dspace-rest-v2.service'; +import {getResponseFromEntry} from '../shared/operators'; @Injectable() export class AuthRequestService { @@ -41,7 +41,9 @@ export class AuthRequestService { public postToEndpoint(method: string, body: any, options?: HttpOptions): Observable { return this.halService.getEndpoint(this.linkName).pipe( filter((href: string) => isNotEmpty(href)), + tap((href: string) => console.log('This is href in postToEndpoint(): ' , href)), map((endpointURL) => this.getEndpointByMethod(endpointURL, method)), + tap((href2) => {console.log('href2', href2)}), distinctUntilChanged(), map((endpointURL: string) => new AuthPostRequest(this.requestService.generateRequestId(), endpointURL, body, options)), tap((request: PostRequest) => this.requestService.configure(request, true)), @@ -53,9 +55,9 @@ export class AuthRequestService { console.log('auth.request getRequest() was called'); return this.halService.getEndpoint(this.linkName).pipe( filter((href: string) => isNotEmpty(href)), - tap((href) => console.log('auth-request.service getRequest()',href)), + tap((href) => console.log('auth-request.service getRequest()', href)), map((endpointURL) => this.getEndpointByMethod(endpointURL, method)), - tap((whatsThis) => console.log('whatsThis: ', whatsThis )), + tap((whatsThis) => console.log('whatsThis: ', whatsThis)), distinctUntilChanged(), map((endpointURL: string) => new AuthGetRequest(this.requestService.generateRequestId(), endpointURL, options)), tap((request: GetRequest) => this.requestService.configure(request, true)), diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index f74ff6e878..c2715a3f01 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -154,10 +154,10 @@ export class AuthInterceptor implements HttpInterceptor { console.log('error.headers.get("location"): ', location); console.log('www-authenticate', error.headers.get('www-authenticate')); - let strings = error.headers.get('www-authenticate').split(','); - let string = strings[1]; - let s = string.replace('location=', ''); - let s1 = s.replace('"', '').trim(); + const strings = error.headers.get('www-authenticate').split(','); + const locationstring = strings[1]; + const s = locationstring.replace('location=', ''); + const s1 = s.replace('"', '').trim(); console.log('This should be the location: ', s1); location = s1; diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html index 19449c4b4d..2f3ff45582 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -27,6 +27,9 @@ {{"login.form.ssoLogin" | translate}} + + + {{"login.form.new-user" | translate}} {{"login.form.forgot-password" | translate}}