Added Action to set isStandAlonePage in store

This commit is contained in:
Julius Gruber
2019-10-17 15:39:33 +02:00
parent 8fde909915
commit 6a2b9dad26
7 changed files with 35 additions and 38 deletions

View File

@@ -8,3 +8,4 @@
</div>
</div>
</div>

View File

@@ -10,7 +10,7 @@ import {
AddAuthenticationMessageAction,
AuthenticatedAction,
AuthenticationSuccessAction,
ResetAuthenticationMessagesAction
ResetAuthenticationMessagesAction, SetIsStandalonePageInAuthMethodsAction
} from '../core/auth/auth.actions';
import { hasValue, isNotEmpty } from '../shared/empty.util';
import { AuthTokenInfo } from '../core/auth/models/auth-token-info.model';
@@ -79,4 +79,5 @@ export class LoginPageComponent implements OnDestroy, OnInit {
// Clear all authentication messages when leaving login page
this.store.dispatch(new ResetAuthenticationMessagesAction());
}
}

View File

@@ -23,6 +23,7 @@ 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'),
@@ -374,6 +375,15 @@ export class RetrieveAuthMethodsErrorAction implements Action {
public type: string = AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR;
}
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.
* @class SetRedirectUrlAction
@@ -413,4 +423,5 @@ export type AuthActions
| ResetAuthenticationMessagesAction
| RetrieveAuthMethodsAction
| RetrieveAuthMethodsSuccessAction
| SetIsStandalonePageInAuthMethodsAction
| RetrieveAuthMethodsErrorAction;

View File

@@ -8,13 +8,14 @@ import {
LogOutErrorAction,
RedirectWhenAuthenticationIsRequiredAction,
RedirectWhenTokenExpiredAction,
RefreshTokenSuccessAction, RetrieveAuthMethodsSuccessAction,
RefreshTokenSuccessAction, RetrieveAuthMethodsSuccessAction, SetIsStandalonePageInAuthMethodsAction,
SetRedirectUrlAction
} from './auth.actions';
// import models
import { EPerson } from '../eperson/models/eperson.model';
import { AuthTokenInfo } from './models/auth-token-info.model';
import { AuthMethodModel } from './models/auth-method.model';
import { AuthMethodType } from '../../shared/log-in/methods/authMethods-type';
/**
* The auth state.
@@ -219,6 +220,16 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
authMethods: (action as RetrieveAuthMethodsSuccessAction).payload
});
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;
for (const authMethod of authMethods) {
const newAuthMethod = new AuthMethodModel(authMethod.authMethodType, authMethod.location, isStandAlonePage);
newAuthMethods.push(newAuthMethod);
}
return Object.assign({}, state, {authMethods: newAuthMethods});
case AuthActionTypes.RETRIEVE_AUTH_METHODS_ERROR:
return Object.assign({}, state, {
loading: false

View File

@@ -6,7 +6,7 @@ export class AuthMethodModel {
location?: string;
isStandalonePage? = true;
constructor(authMethodName: string, location?: string) {
constructor(authMethodName: string, location?: string, isStandAlonePage?: boolean) {
switch (authMethodName) {
case 'ip': {
this.authMethodType = AuthMethodType.Ip;

View File

@@ -1,13 +0,0 @@
import { AuthMethodType } from '../../../shared/log-in/methods/authMethods-type';
export class InjectedAuthMethodModel {
authMethodType: AuthMethodType;
location?: string;
isStandalonePage?: boolean;
constructor(authMethodName: AuthMethodType, location?: string, isStandAlonePage?: boolean) {
this.authMethodType = authMethodName;
this.location = location;
this.isStandalonePage = isStandAlonePage;
}
}

View File

@@ -1,12 +1,12 @@
import { Component, Injector, Input, OnDestroy, OnInit } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { AuthMethodModel } from '../../core/auth/models/auth-method.model';
import { select, Store } from '@ngrx/store';
import { getAuthenticationMethods, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
import { CoreState } from '../../core/core.reducers';
import { InjectedAuthMethodModel } from './injectedAuthMethodModel/injectedAuthMethodModel';
import { filter, takeWhile, tap } from 'rxjs/operators';
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',
@@ -20,10 +20,6 @@ export class LogInComponent implements OnInit, OnDestroy {
*/
@Input() authMethodData: Observable<AuthMethodModel[]>;
// private authMethods: AuthMethodModel[];
// public injectedAuthMethods: InjectedAuthMethodModel[];
@Input() isStandalonePage: boolean;
/**
@@ -44,26 +40,17 @@ export class LogInComponent implements OnInit, OnDestroy {
*/
private alive = true;
private subscription: Subscription;
constructor(private store: Store<CoreState>,
private authService: AuthService,) {
}
ngOnInit(): void {
this.store.dispatch(new SetIsStandalonePageInAuthMethodsAction(this.isStandalonePage));
this.authMethodData = this.store.pipe(
select(getAuthenticationMethods)
select(getAuthenticationMethods),
);
/*
this.subscription = this.authMethodData.subscribe((methods) => this.authMethods = methods);
this.injectedAuthMethods = new Array<InjectedAuthMethodModel>();
// tslint:disable-next-line:forin
for (const index in this.authMethods) {
const injectedAuthMethod = new InjectedAuthMethodModel(this.authMethods[index].authMethodType, this.authMethods[index].location, this.isStandalonePage);
this.injectedAuthMethods.push(injectedAuthMethod);
}
console.log('injectedAuthMethods in ngOnInit(): ', this.injectedAuthMethods);
*/
// set loading
this.loading = this.store.pipe(select(isAuthenticationLoading));
@@ -84,7 +71,6 @@ export class LogInComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
// this.subscription.unsubscribe();
this.alive = false;
}