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,
AuthenticatedAction,
AuthenticationSuccessAction,
ResetAuthenticationMessagesAction, SetIsStandalonePageInAuthMethodsAction
ResetAuthenticationMessagesAction
} from '../core/auth/auth.actions';
import { hasValue, isNotEmpty } from '../shared/empty.util';
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_SUCCESS: type('dspace/auth/RETRIEVE_AUTH_METHODS_SUCCESS'),
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_AUTHENTICATION_REQUIRED: type('dspace/auth/REDIRECT_AUTHENTICATION_REQUIRED'),
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 {
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;
payload: boolean;
constructor(isStandAlonePage: boolean) {
this.payload = isStandAlonePage;
}
}
}*/
/**
* Change the redirect url.
@@ -423,5 +417,4 @@ export type AuthActions
| ResetAuthenticationMessagesAction
| RetrieveAuthMethodsAction
| RetrieveAuthMethodsSuccessAction
| SetIsStandalonePageInAuthMethodsAction
| RetrieveAuthMethodsErrorAction;

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,6 @@ import { Store } from '@ngrx/store';
import { CoreState } from '../../../core/core.reducers';
import { AuthMethodModel } from '../../../core/auth/models/auth-method.model';
/**
* 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
*/
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 { filter, takeWhile, } from 'rxjs/operators';
import { AuthService } from '../../core/auth/auth.service';
import { SetIsStandalonePageInAuthMethodsAction } from '../../core/auth/auth.actions';
@Component({
selector: 'ds-log-in',
@@ -46,7 +45,7 @@ export class LogInComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage));
// this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage));
this.authMethodData = this.store.pipe(
select(getAuthenticationMethods),

View File

@@ -1,4 +1,3 @@
<!--*ngIf="!(loading | async) && !(isAuthenticated | async)" class="form-login px-4 py-3"-->
<form (ngSubmit)="submit()"
[formGroup]="form" novalidate>
<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 { select, Store } from '@ngrx/store';
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 {
isAuthenticated,
@@ -58,6 +58,7 @@ export class LogInShibbolethComponent implements OnInit {
}
submit() {
this.store.dispatch(new SetRedirectUrlAction('/mytest/url'));
this.store.dispatch(new StartShibbolethAuthenticationAction(this.authMethodModel));
// https://host/Shibboleth.sso/Login?target=https://host/shibboleth
window.location.href = this.injectedAuthMethodModel.location;