diff --git a/src/app/+login-page/login-page.component.html b/src/app/+login-page/login-page.component.html index 8c050fd188..239d62a12f 100644 --- a/src/app/+login-page/login-page.component.html +++ b/src/app/+login-page/login-page.component.html @@ -8,3 +8,4 @@ + diff --git a/src/app/+login-page/login-page.component.ts b/src/app/+login-page/login-page.component.ts index 6a8508eb45..0a249022d5 100644 --- a/src/app/+login-page/login-page.component.ts +++ b/src/app/+login-page/login-page.component.ts @@ -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()); } + } diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index 644cce9e22..5913347c4c 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -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; diff --git a/src/app/core/auth/auth.reducer.ts b/src/app/core/auth/auth.reducer.ts index a23c8cceea..a7882dd912 100644 --- a/src/app/core/auth/auth.reducer.ts +++ b/src/app/core/auth/auth.reducer.ts @@ -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(); + 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 diff --git a/src/app/core/auth/models/auth-method.model.ts b/src/app/core/auth/models/auth-method.model.ts index 7cac8f33ce..81cb5f6777 100644 --- a/src/app/core/auth/models/auth-method.model.ts +++ b/src/app/core/auth/models/auth-method.model.ts @@ -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; diff --git a/src/app/shared/log-in/injectedAuthMethodModel/injectedAuthMethodModel.ts b/src/app/shared/log-in/injectedAuthMethodModel/injectedAuthMethodModel.ts deleted file mode 100644 index 373460f88b..0000000000 --- a/src/app/shared/log-in/injectedAuthMethodModel/injectedAuthMethodModel.ts +++ /dev/null @@ -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; - } -} diff --git a/src/app/shared/log-in/log-in.component.ts b/src/app/shared/log-in/log-in.component.ts index 952e7e8286..026fe8d867 100644 --- a/src/app/shared/log-in/log-in.component.ts +++ b/src/app/shared/log-in/log-in.component.ts @@ -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; - // 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, 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(); - // 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; }