Cache redesign part 1, and add support for alternative links

This commit is contained in:
Art Lowel
2020-12-11 14:18:44 +01:00
parent f4853972cc
commit 4e18fa35ca
522 changed files with 7537 additions and 6933 deletions

View File

@@ -10,7 +10,7 @@ import { CookieAttributes } from 'js-cookie';
import { EPerson } from '../eperson/models/eperson.model';
import { AuthRequestService } from './auth-request.service';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
import { AuthStatus } from './models/auth-status.model';
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
import {
@@ -44,6 +44,7 @@ import { EPersonDataService } from '../eperson/eperson-data.service';
import { getAllSucceededRemoteDataPayload } from '../shared/operators';
import { AuthMethod } from './models/auth.method';
import { HardRedirectService } from '../services/hard-redirect.service';
import { RemoteData } from '../data/remote-data';
export const LOGIN_ROUTE = '/login';
export const LOGOUT_ROUTE = '/logout';
@@ -94,9 +95,9 @@ export class AuthService {
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
options.headers = headers;
return this.authRequestService.postToEndpoint('login', body, options).pipe(
map((status: AuthStatus) => {
if (status.authenticated) {
return status;
map((rd: RemoteData<AuthStatus>) => {
if (hasValue(rd.payload) && rd.payload.authenticated) {
return rd.payload;
} else {
throw(new Error('Invalid email or password'));
}
@@ -115,7 +116,7 @@ export class AuthService {
options.headers = headers;
options.withCredentials = true;
return this.authRequestService.getRequest('status', options).pipe(
map((status: AuthStatus) => Object.assign(new AuthStatus(), status))
map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload))
);
}
@@ -147,8 +148,9 @@ export class AuthService {
headers = headers.append('Authorization', `Bearer ${token.accessToken}`);
options.headers = headers;
return this.authRequestService.getRequest('status', options).pipe(
map((status: AuthStatus) => {
if (status.authenticated) {
map((rd: RemoteData<AuthStatus>) => {
const status = rd.payload;
if (hasValue(status) && status.authenticated) {
return status._links.eperson.href;
} else {
throw(new Error('Not authenticated'));
@@ -229,8 +231,9 @@ export class AuthService {
options.headers = headers;
options.withCredentials = true;
return this.authRequestService.postToEndpoint('login', {}, options).pipe(
map((status: AuthStatus) => {
if (status.authenticated) {
map((rd: RemoteData<AuthStatus>) => {
const status = rd.payload;
if (hasValue(status) && status.authenticated) {
return status.token;
} else {
throw(new Error('Not authenticated'));
@@ -267,8 +270,9 @@ export class AuthService {
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
const options: HttpOptions = Object.create({ headers, responseType: 'text' });
return this.authRequestService.getRequest('logout', options).pipe(
map((status: AuthStatus) => {
if (!status.authenticated) {
map((rd: RemoteData<AuthStatus>) => {
const status = rd.payload;
if (hasValue(status) && !status.authenticated) {
return true;
} else {
throw(new Error('auth.errors.invalid-user'));