Added action to retrieve authenticated eperson object

This commit is contained in:
Giuseppe Digilio
2020-03-02 13:09:17 +01:00
parent df8ef2b5c3
commit 18e17f0dad
11 changed files with 281 additions and 83 deletions

View File

@@ -1,9 +1,7 @@
// import @ngrx
import { Action } from '@ngrx/store';
// import type function
import { type } from '../../shared/ngrx/type';
// import models
import { EPerson } from '../eperson/models/eperson.model';
import { AuthTokenInfo } from './models/auth-token-info.model';
@@ -31,6 +29,9 @@ export const AuthActionTypes = {
REGISTRATION_ERROR: type('dspace/auth/REGISTRATION_ERROR'),
REGISTRATION_SUCCESS: type('dspace/auth/REGISTRATION_SUCCESS'),
SET_REDIRECT_URL: type('dspace/auth/SET_REDIRECT_URL'),
RETRIEVE_AUTHENTICATED_EPERSON: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON'),
RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS'),
RETRIEVE_AUTHENTICATED_EPERSON_ERROR: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON_ERROR'),
};
/* tslint:disable:max-classes-per-file */
@@ -76,11 +77,11 @@ export class AuthenticatedSuccessAction implements Action {
payload: {
authenticated: boolean;
authToken: AuthTokenInfo;
user: EPerson
userHref: string
};
constructor(authenticated: boolean, authToken: AuthTokenInfo, user: EPerson) {
this.payload = { authenticated, authToken, user };
constructor(authenticated: boolean, authToken: AuthTokenInfo, userHref: string) {
this.payload = { authenticated, authToken, userHref };
}
}
@@ -322,6 +323,47 @@ export class SetRedirectUrlAction implements Action {
}
}
/**
* Retrieve the authenticated eperson.
* @class RetrieveAuthenticatedEpersonAction
* @implements {Action}
*/
export class RetrieveAuthenticatedEpersonAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON;
payload: string;
constructor(user: string) {
this.payload = user ;
}
}
/**
* Set the authenticated eperson in the state.
* @class RetrieveAuthenticatedEpersonSuccessAction
* @implements {Action}
*/
export class RetrieveAuthenticatedEpersonSuccessAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS;
payload: EPerson;
constructor(user: EPerson) {
this.payload = user ;
}
}
/**
* Set the authenticated eperson in the state.
* @class RetrieveAuthenticatedEpersonSuccessAction
* @implements {Action}
*/
export class RetrieveAuthenticatedEpersonErrorAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_ERROR;
payload: Error;
constructor(payload: Error) {
this.payload = payload ;
}
}
/* tslint:enable:max-classes-per-file */
/**
@@ -343,4 +385,8 @@ export type AuthActions
| RegistrationErrorAction
| RegistrationSuccessAction
| AddAuthenticationMessageAction
| ResetAuthenticationMessagesAction;
| ResetAuthenticationMessagesAction
| RetrieveAuthenticatedEpersonAction
| RetrieveAuthenticatedEpersonErrorAction
| RetrieveAuthenticatedEpersonSuccessAction
| SetRedirectUrlAction;