Removed isStandAlone from store

This commit is contained in:
Julius Gruber
2019-10-18 08:58:36 +02:00
parent 392b539036
commit 792f7bf74d
9 changed files with 67 additions and 78 deletions

View File

@@ -10,7 +10,7 @@ import {
AddAuthenticationMessageAction, AddAuthenticationMessageAction,
AuthenticatedAction, AuthenticatedAction,
AuthenticationSuccessAction, AuthenticationSuccessAction,
ResetAuthenticationMessagesAction, SetIsStandalonePageInAuthMethodsAction ResetAuthenticationMessagesAction
} from '../core/auth/auth.actions'; } from '../core/auth/auth.actions';
import { hasValue, isNotEmpty } from '../shared/empty.util'; import { hasValue, isNotEmpty } from '../shared/empty.util';
import { AuthTokenInfo } from '../core/auth/models/auth-token-info.model'; import { AuthTokenInfo } from '../core/auth/models/auth-token-info.model';

View File

@@ -23,7 +23,6 @@ export const AuthActionTypes = {
RETRIEVE_AUTH_METHODS: type('dspace/auth/RETRIEVE_AUTH_METHODS'), RETRIEVE_AUTH_METHODS: type('dspace/auth/RETRIEVE_AUTH_METHODS'),
RETRIEVE_AUTH_METHODS_SUCCESS: type('dspace/auth/RETRIEVE_AUTH_METHODS_SUCCESS'), RETRIEVE_AUTH_METHODS_SUCCESS: type('dspace/auth/RETRIEVE_AUTH_METHODS_SUCCESS'),
RETRIEVE_AUTH_METHODS_ERROR: type('dspace/auth/RETRIEVE_AUTH_METHODS_ERROR'), RETRIEVE_AUTH_METHODS_ERROR: type('dspace/auth/RETRIEVE_AUTH_METHODS_ERROR'),
SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS: type('dspace/auth/SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS'),
REDIRECT_TOKEN_EXPIRED: type('dspace/auth/REDIRECT_TOKEN_EXPIRED'), REDIRECT_TOKEN_EXPIRED: type('dspace/auth/REDIRECT_TOKEN_EXPIRED'),
REDIRECT_AUTHENTICATION_REQUIRED: type('dspace/auth/REDIRECT_AUTHENTICATION_REQUIRED'), REDIRECT_AUTHENTICATION_REQUIRED: type('dspace/auth/REDIRECT_AUTHENTICATION_REQUIRED'),
REFRESH_TOKEN: type('dspace/auth/REFRESH_TOKEN'), REFRESH_TOKEN: type('dspace/auth/REFRESH_TOKEN'),
@@ -366,23 +365,18 @@ export class RetrieveAuthMethodsSuccessAction implements Action {
} }
} }
/**
* Check if token is already present upon initial load.
* @class CheckAuthenticationTokenAction
* @implements {Action}
*/
export class RetrieveAuthMethodsErrorAction implements Action { export class RetrieveAuthMethodsErrorAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR; public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR;
} }
export class SetIsStandalonePageInAuthMethodsAction implements Action { /*export class SetIsStandalonePageInAuthMethodsAction implements Action {
type: string = AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS; type: string = AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS;
payload: boolean; payload: boolean;
constructor(isStandAlonePage: boolean) { constructor(isStandAlonePage: boolean) {
this.payload = isStandAlonePage; this.payload = isStandAlonePage;
} }
} }*/
/** /**
* Change the redirect url. * Change the redirect url.
@@ -423,5 +417,4 @@ export type AuthActions
| ResetAuthenticationMessagesAction | ResetAuthenticationMessagesAction
| RetrieveAuthMethodsAction | RetrieveAuthMethodsAction
| RetrieveAuthMethodsSuccessAction | RetrieveAuthMethodsSuccessAction
| SetIsStandalonePageInAuthMethodsAction
| RetrieveAuthMethodsErrorAction; | RetrieveAuthMethodsErrorAction;

View File

@@ -28,9 +28,8 @@ import {
RegistrationErrorAction, RegistrationErrorAction,
RegistrationSuccessAction, RegistrationSuccessAction,
RetrieveAuthMethodsAction, RetrieveAuthMethodsAction,
RetrieveAuthMethodsErrorAction,
RetrieveAuthMethodsSuccessAction, RetrieveAuthMethodsSuccessAction,
GetJWTafterShibbLoginAction, StartShibbolethAuthenticationAction GetJWTafterShibbLoginAction, StartShibbolethAuthenticationAction, RetrieveAuthMethodsErrorAction
} from './auth.actions'; } from './auth.actions';
import { EPerson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
import { AuthStatus } from './models/auth-status.model'; import { AuthStatus } from './models/auth-status.model';
@@ -76,79 +75,79 @@ export class AuthEffects {
@Effect() @Effect()
public authenticateSuccess$: Observable<Action> = this.actions$.pipe( public authenticateSuccess$: Observable<Action> = this.actions$.pipe(
ofType(AuthActionTypes.AUTHENTICATE_SUCCESS), ofType(AuthActionTypes.AUTHENTICATE_SUCCESS),
tap((action: AuthenticationSuccessAction) => this.authService.storeToken(action.payload)), tap((action: AuthenticationSuccessAction) => this.authService.storeToken(action.payload)),
map((action: AuthenticationSuccessAction) => new AuthenticatedAction(action.payload)) map((action: AuthenticationSuccessAction) => new AuthenticatedAction(action.payload))
); );
@Effect() @Effect()
public authenticated$: Observable<Action> = this.actions$.pipe( public authenticated$: Observable<Action> = this.actions$.pipe(
ofType(AuthActionTypes.AUTHENTICATED), ofType(AuthActionTypes.AUTHENTICATED),
switchMap((action: AuthenticatedAction) => { switchMap((action: AuthenticatedAction) => {
return this.authService.authenticatedUser(action.payload).pipe( return this.authService.authenticatedUser(action.payload).pipe(
map((user: EPerson) => new AuthenticatedSuccessAction((user !== null), action.payload, user)), map((user: EPerson) => new AuthenticatedSuccessAction((user !== null), action.payload, user)),
catchError((error) => observableOf(new AuthenticatedErrorAction(error))),); catchError((error) => observableOf(new AuthenticatedErrorAction(error))),);
}) })
); );
// It means "reacts to this action but don't send another" // It means "reacts to this action but don't send another"
@Effect({ dispatch: false }) @Effect({dispatch: false})
public authenticatedError$: Observable<Action> = this.actions$.pipe( public authenticatedError$: Observable<Action> = this.actions$.pipe(
ofType(AuthActionTypes.AUTHENTICATED_ERROR), ofType(AuthActionTypes.AUTHENTICATED_ERROR),
tap((action: LogOutSuccessAction) => this.authService.removeToken()) tap((action: LogOutSuccessAction) => this.authService.removeToken())
); );
@Effect() @Effect()
public checkToken$: Observable<Action> = this.actions$.pipe(ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN), public checkToken$: Observable<Action> = this.actions$.pipe(ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN),
switchMap(() => { switchMap(() => {
return this.authService.hasValidAuthenticationToken().pipe( return this.authService.hasValidAuthenticationToken().pipe(
map((token: AuthTokenInfo) => new AuthenticatedAction(token)), map((token: AuthTokenInfo) => new AuthenticatedAction(token)),
catchError((error) => observableOf(new CheckAuthenticationTokenErrorAction())) catchError((error) => observableOf(new CheckAuthenticationTokenErrorAction()))
); );
}) })
); );
@Effect() @Effect()
public checkTokenError$: Observable<Action> = this.actions$ public checkTokenError$: Observable<Action> = this.actions$
.pipe( .pipe(
ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_ERROR), ofType(AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_ERROR),
map(() => new RetrieveAuthMethodsAction()) map(() => new RetrieveAuthMethodsAction())
) )
@Effect() @Effect()
public createUser$: Observable<Action> = this.actions$.pipe( public createUser$: Observable<Action> = this.actions$.pipe(
ofType(AuthActionTypes.REGISTRATION), ofType(AuthActionTypes.REGISTRATION),
debounceTime(500), // to remove when functionality is implemented debounceTime(500), // to remove when functionality is implemented
switchMap((action: RegistrationAction) => { switchMap((action: RegistrationAction) => {
return this.authService.create(action.payload).pipe( return this.authService.create(action.payload).pipe(
map((user: EPerson) => new RegistrationSuccessAction(user)), map((user: EPerson) => new RegistrationSuccessAction(user)),
catchError((error) => observableOf(new RegistrationErrorAction(error))) catchError((error) => observableOf(new RegistrationErrorAction(error)))
); );
}) })
); );
@Effect() @Effect()
public refreshToken$: Observable<Action> = this.actions$.pipe(ofType(AuthActionTypes.REFRESH_TOKEN), public refreshToken$: Observable<Action> = this.actions$.pipe(ofType(AuthActionTypes.REFRESH_TOKEN),
switchMap((action: RefreshTokenAction) => { switchMap((action: RefreshTokenAction) => {
return this.authService.refreshAuthenticationToken(action.payload).pipe( return this.authService.refreshAuthenticationToken(action.payload).pipe(
map((token: AuthTokenInfo) => new RefreshTokenSuccessAction(token)), map((token: AuthTokenInfo) => new RefreshTokenSuccessAction(token)),
catchError((error) => observableOf(new RefreshTokenErrorAction())) catchError((error) => observableOf(new RefreshTokenErrorAction()))
); );
}) })
); );
// It means "reacts to this action but don't send another" // It means "reacts to this action but don't send another"
@Effect({ dispatch: false }) @Effect({dispatch: false})
public refreshTokenSuccess$: Observable<Action> = this.actions$.pipe( public refreshTokenSuccess$: Observable<Action> = this.actions$.pipe(
ofType(AuthActionTypes.REFRESH_TOKEN_SUCCESS), ofType(AuthActionTypes.REFRESH_TOKEN_SUCCESS),
tap((action: RefreshTokenSuccessAction) => this.authService.replaceToken(action.payload)) tap((action: RefreshTokenSuccessAction) => this.authService.replaceToken(action.payload))
); );
/** /**
* When the store is rehydrated in the browser, * When the store is rehydrated in the browser,
* clear a possible invalid token or authentication errors * clear a possible invalid token or authentication errors
*/ */
@Effect({ dispatch: false }) @Effect({dispatch: false})
public clearInvalidTokenOnRehydrate$: Observable<any> = this.actions$.pipe( public clearInvalidTokenOnRehydrate$: Observable<any> = this.actions$.pipe(
ofType(StoreActionTypes.REHYDRATE), ofType(StoreActionTypes.REHYDRATE),
switchMap(() => { switchMap(() => {
@@ -173,7 +172,7 @@ export class AuthEffects {
}) })
); );
@Effect({ dispatch: false }) @Effect({dispatch: false})
public logOutSuccess$: Observable<Action> = this.actions$ public logOutSuccess$: Observable<Action> = this.actions$
.pipe(ofType(AuthActionTypes.LOG_OUT_SUCCESS), .pipe(ofType(AuthActionTypes.LOG_OUT_SUCCESS),
tap(() => this.authService.removeToken()), tap(() => this.authService.removeToken()),
@@ -181,14 +180,14 @@ export class AuthEffects {
tap(() => this.authService.refreshAfterLogout()) tap(() => this.authService.refreshAfterLogout())
); );
@Effect({ dispatch: false }) @Effect({dispatch: false})
public redirectToLogin$: Observable<Action> = this.actions$ public redirectToLogin$: Observable<Action> = this.actions$
.pipe(ofType(AuthActionTypes.REDIRECT_AUTHENTICATION_REQUIRED), .pipe(ofType(AuthActionTypes.REDIRECT_AUTHENTICATION_REQUIRED),
tap(() => this.authService.removeToken()), tap(() => this.authService.removeToken()),
tap(() => this.authService.redirectToLogin()) tap(() => this.authService.redirectToLogin())
); );
@Effect({ dispatch: false }) @Effect({dispatch: false})
public redirectToLoginTokenExpired$: Observable<Action> = this.actions$ public redirectToLoginTokenExpired$: Observable<Action> = this.actions$
.pipe( .pipe(
ofType(AuthActionTypes.REDIRECT_TOKEN_EXPIRED), ofType(AuthActionTypes.REDIRECT_TOKEN_EXPIRED),
@@ -201,12 +200,12 @@ export class AuthEffects {
.pipe( .pipe(
ofType(AuthActionTypes.RETRIEVE_AUTH_METHODS), ofType(AuthActionTypes.RETRIEVE_AUTH_METHODS),
switchMap(() => { switchMap(() => {
return this.authService.retrieveAuthMethods() return this.authService.retrieveAuthMethods()
.pipe( .pipe(
map((location: any) => new RetrieveAuthMethodsSuccessAction(location)), map((location: any) => new RetrieveAuthMethodsSuccessAction(location)),
catchError((error) => observableOf(new RetrieveAuthMethodsErrorAction())) catchError((error) => observableOf(new RetrieveAuthMethodsErrorAction()))
) )
}) })
) )
/** /**

View File

@@ -8,7 +8,7 @@ import {
LogOutErrorAction, LogOutErrorAction,
RedirectWhenAuthenticationIsRequiredAction, RedirectWhenAuthenticationIsRequiredAction,
RedirectWhenTokenExpiredAction, RedirectWhenTokenExpiredAction,
RefreshTokenSuccessAction, RetrieveAuthMethodsSuccessAction, SetIsStandalonePageInAuthMethodsAction, RefreshTokenSuccessAction, RetrieveAuthMethodsSuccessAction,
SetRedirectUrlAction SetRedirectUrlAction
} from './auth.actions'; } from './auth.actions';
// import models // import models
@@ -220,7 +220,7 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
authMethods: (action as RetrieveAuthMethodsSuccessAction).payload authMethods: (action as RetrieveAuthMethodsSuccessAction).payload
}); });
case AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS: /* case AuthActionTypes.SET_IS_STANDALONE_PAGE_IN_AUTH_METHODS:
const authMethods: AuthMethodModel[] = state.authMethods; const authMethods: AuthMethodModel[] = state.authMethods;
const newAuthMethods: AuthMethodModel[] = new Array<AuthMethodModel>(); const newAuthMethods: AuthMethodModel[] = new Array<AuthMethodModel>();
const isStandAlonePage: boolean = (action as SetIsStandalonePageInAuthMethodsAction).payload; const isStandAlonePage: boolean = (action as SetIsStandalonePageInAuthMethodsAction).payload;
@@ -228,7 +228,7 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
const newAuthMethod = new AuthMethodModel(authMethod.authMethodType, authMethod.location, isStandAlonePage); const newAuthMethod = new AuthMethodModel(authMethod.authMethodType, authMethod.location, isStandAlonePage);
newAuthMethods.push(newAuthMethod); newAuthMethods.push(newAuthMethod);
} }
return Object.assign({}, state, {authMethods: newAuthMethods}); return Object.assign({}, state, {authMethods: newAuthMethods});*/
case AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR: case AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR:
return Object.assign({}, state, { return Object.assign({}, state, {

View File

@@ -4,9 +4,9 @@ import { ShibbConstants } from '../../../+login-page/shibbolethTargetPage/const/
export class AuthMethodModel { export class AuthMethodModel {
authMethodType: AuthMethodType; authMethodType: AuthMethodType;
location?: string; location?: string;
isStandalonePage? = true; // isStandalonePage? = true;
constructor(authMethodName: string, location?: string, isStandAlonePage?: boolean) { constructor(authMethodName: string, location?: string) {
switch (authMethodName) { switch (authMethodName) {
case 'ip': { case 'ip': {
this.authMethodType = AuthMethodType.Ip; this.authMethodType = AuthMethodType.Ip;

View File

@@ -4,7 +4,6 @@ import { Store } from '@ngrx/store';
import { CoreState } from '../../../core/core.reducers'; import { CoreState } from '../../../core/core.reducers';
import { AuthMethodModel } from '../../../core/auth/models/auth-method.model'; import { AuthMethodModel } from '../../../core/auth/models/auth-method.model';
/** /**
* This component represents a section that contains the submission license form. * This component represents a section that contains the submission license form.
*/ */
@@ -47,8 +46,7 @@ export class LoginContainerComponent implements OnInit {
* Find the correct component based on the AuthMethod's type * Find the correct component based on the AuthMethod's type
*/ */
getAuthMethodContent(): string { getAuthMethodContent(): string {
console.log('Trying to render login component for type: ', this.authMethodModel.authMethodType); return rendersAuthMethodType(this.authMethodModel.authMethodType)
return rendersAuthMethodType(this.authMethodModel.authMethodType)
} }
} }

View File

@@ -6,7 +6,6 @@ import { getAuthenticationMethods, isAuthenticated, isAuthenticationLoading } fr
import { CoreState } from '../../core/core.reducers'; import { CoreState } from '../../core/core.reducers';
import { filter, takeWhile, } from 'rxjs/operators'; import { filter, takeWhile, } from 'rxjs/operators';
import { AuthService } from '../../core/auth/auth.service'; import { AuthService } from '../../core/auth/auth.service';
import { SetIsStandalonePageInAuthMethodsAction } from '../../core/auth/auth.actions';
@Component({ @Component({
selector: 'ds-log-in', selector: 'ds-log-in',
@@ -46,7 +45,7 @@ export class LogInComponent implements OnInit, OnDestroy {
ngOnInit(): void { ngOnInit(): void {
this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage)); // this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage));
this.authMethodData = this.store.pipe( this.authMethodData = this.store.pipe(
select(getAuthenticationMethods), select(getAuthenticationMethods),

View File

@@ -1,4 +1,3 @@
<!--*ngIf="!(loading | async) && !(isAuthenticated | async)" class="form-login px-4 py-3"-->
<form (ngSubmit)="submit()" <form (ngSubmit)="submit()"
[formGroup]="form" novalidate> [formGroup]="form" novalidate>
<label for="inputEmail" class="sr-only">{{"login.form.email" | translate}}</label> <label for="inputEmail" class="sr-only">{{"login.form.email" | translate}}</label>

View File

@@ -10,7 +10,7 @@ import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model'
import { FormBuilder } from '@angular/forms'; import { FormBuilder } from '@angular/forms';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
import { CoreState } from '../../../../core/core.reducers'; import { CoreState } from '../../../../core/core.reducers';
import { StartShibbolethAuthenticationAction } from '../../../../core/auth/auth.actions'; import { SetRedirectUrlAction, StartShibbolethAuthenticationAction } from '../../../../core/auth/auth.actions';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { import {
isAuthenticated, isAuthenticated,
@@ -58,6 +58,7 @@ export class LogInShibbolethComponent implements OnInit {
} }
submit() { submit() {
this.store.dispatch(new SetRedirectUrlAction('/mytest/url'));
this.store.dispatch(new StartShibbolethAuthenticationAction(this.authMethodModel)); this.store.dispatch(new StartShibbolethAuthenticationAction(this.authMethodModel));
// https://host/Shibboleth.sso/Login?target=https://host/shibboleth // https://host/Shibboleth.sso/Login?target=https://host/shibboleth
window.location.href = this.injectedAuthMethodModel.location; window.location.href = this.injectedAuthMethodModel.location;