diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index cf7f325653..644cce9e22 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -341,10 +341,10 @@ export class ResetAuthenticationMessagesAction implements Action { public type: string = AuthActionTypes.RESET_MESSAGES; } -// Next three Actions are used by shibboleth login +// // Next three Actions are used by dynamic login methods /** - * Check if token is already present upon initial load. - * @class CheckAuthenticationTokenAction + * Action that triggers an effect fetching the authentication methods enabled ant the backend + * @class RetrieveAuthMethodsAction * @implements {Action} */ export class RetrieveAuthMethodsAction implements Action { diff --git a/src/app/core/auth/models/auth-method.model.ts b/src/app/core/auth/models/auth-method.model.ts index f5a506be2a..9aba68b2ef 100644 --- a/src/app/core/auth/models/auth-method.model.ts +++ b/src/app/core/auth/models/auth-method.model.ts @@ -1,12 +1,13 @@ -import {AuthMethodType} from '../../../shared/log-in/methods/authMethods-type'; +import { AuthMethodType } from '../../../shared/log-in/methods/authMethods-type'; import { ShibbConstants } from '../../../+login-page/shibbolethTargetPage/const/shibbConstants'; export class AuthMethodModel { authMethodType: AuthMethodType; location?: string; + isStandalonePage?: boolean; - constructor(authMethodName: string, location?: string) { - switch (authMethodName) { + constructor(authMethodName: string, location?: string, isStandAlonePage?: boolean) { + switch (authMethodName) { case 'ip': { this.authMethodType = AuthMethodType.Ip; break; @@ -19,9 +20,6 @@ export class AuthMethodModel { this.authMethodType = AuthMethodType.Shibboleth; const strings: string[] = location.split('target='); const target = strings[1]; - - console.log('strings', strings); - this.location = target + location + '/' + ShibbConstants.SHIBBOLETH_REDIRECT_ROUTE; break; } @@ -31,6 +29,7 @@ export class AuthMethodModel { } case 'password': { this.authMethodType = AuthMethodType.Password; + this.isStandalonePage = true; break; } diff --git a/src/app/shared/log-in/container/login-container.component.html b/src/app/shared/log-in/container/login-container.component.html index cc73919710..bef6f43b66 100644 --- a/src/app/shared/log-in/container/login-container.component.html +++ b/src/app/shared/log-in/container/login-container.component.html @@ -1,3 +1,5 @@ - + diff --git a/src/app/shared/log-in/container/login-container.component.ts b/src/app/shared/log-in/container/login-container.component.ts index 2abaeb04c3..b14da99afe 100644 --- a/src/app/shared/log-in/container/login-container.component.ts +++ b/src/app/shared/log-in/container/login-container.component.ts @@ -3,6 +3,7 @@ import { rendersAuthMethodType } from '../methods/authMethods-decorator'; import { AuthMethodModel } from '../../../core/auth/models/auth-method.model'; import { select, Store } from '@ngrx/store'; import { CoreState } from '../../../core/core.reducers'; +import { InjectedAuthMethodModel } from '../injectedAuthMethodModel/injectedAuthMethodModel'; /** * This component represents a section that contains the submission license form. @@ -14,7 +15,7 @@ import { CoreState } from '../../../core/core.reducers'; }) export class LoginContainerComponent implements OnInit { - @Input() authMethodModel: AuthMethodModel; + @Input() authMethodModel: InjectedAuthMethodModel; /** * Injector to inject a section component with the @Input parameters diff --git a/src/app/shared/log-in/injectedAuthMethodModel/injectedAuthMethodModel.ts b/src/app/shared/log-in/injectedAuthMethodModel/injectedAuthMethodModel.ts new file mode 100644 index 0000000000..373460f88b --- /dev/null +++ b/src/app/shared/log-in/injectedAuthMethodModel/injectedAuthMethodModel.ts @@ -0,0 +1,13 @@ +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.html b/src/app/shared/log-in/log-in.component.html index 1af185c707..ebcc29f914 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -1,4 +1,5 @@ - - + + diff --git a/src/app/shared/log-in/log-in.component.ts b/src/app/shared/log-in/log-in.component.ts index 9e6697c170..81c52830a9 100644 --- a/src/app/shared/log-in/log-in.component.ts +++ b/src/app/shared/log-in/log-in.component.ts @@ -1,22 +1,27 @@ -import { Component, Injector, Input, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; +import { Component, Injector, Input, OnDestroy, OnInit } from '@angular/core'; +import { Observable, Subscription } 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'; @Component({ selector: 'ds-log-in', templateUrl: './log-in.component.html', styleUrls: ['./log-in.component.scss'] }) -export class LogInComponent implements OnInit { +export class LogInComponent implements OnInit, OnDestroy { /** * The authentication methods data * @type {AuthMethodModel[]} */ @Input() authMethodData: Observable; + private authMethods: AuthMethodModel[]; + + private injectedAuthMethods: InjectedAuthMethodModel[]; + @Input() isStandalonePage: boolean; /** @@ -30,13 +35,22 @@ export class LogInComponent implements OnInit { * @type {boolean} */ public loading: Observable; + private subscription: Subscription; - constructor( private store: Store) { + constructor(private store: Store) { } ngOnInit(): void { this.authMethodData = this.store.pipe(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); + } + // set loading this.loading = this.store.pipe(select(isAuthenticationLoading)); @@ -44,4 +58,8 @@ export class LogInComponent implements OnInit { this.isAuthenticated = this.store.pipe(select(isAuthenticated)); } + ngOnDestroy(): void { + this.subscription.unsubscribe(); + } + } diff --git a/src/app/shared/log-in/methods/password/log-in-password.component.ts b/src/app/shared/log-in/methods/password/log-in-password.component.ts index 564e4174e5..a5710d48a1 100644 --- a/src/app/shared/log-in/methods/password/log-in-password.component.ts +++ b/src/app/shared/log-in/methods/password/log-in-password.component.ts @@ -1,5 +1,5 @@ import { filter, map, takeWhile } from 'rxjs/operators'; -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, Inject, Input, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { select, Store } from '@ngrx/store'; @@ -22,6 +22,7 @@ import { fadeOut } from '../../../animations/fade'; import { AuthService } from '../../../../core/auth/auth.service'; import { AuthMethodType } from '../authMethods-type'; import { renderAuthMethodFor } from '../authMethods-decorator'; +import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model'; /** * /users/sign-in @@ -84,6 +85,8 @@ export class LogInPasswordComponent implements OnDestroy, OnInit { */ private alive = true; + @Input() authMethodModel: AuthMethodModel; + /** * @constructor * @param {AuthService} authService @@ -91,10 +94,12 @@ export class LogInPasswordComponent implements OnDestroy, OnInit { * @param {Store} store */ constructor( + @Inject('authMethodModelProvider') public injectedAuthMethodModel: AuthMethodModel, private authService: AuthService, private formBuilder: FormBuilder, - private store: Store, + private store: Store ) { + this.authMethodModel = injectedAuthMethodModel; } /** @@ -102,7 +107,6 @@ export class LogInPasswordComponent implements OnDestroy, OnInit { * @method ngOnInit */ public ngOnInit() { - // set isAuthenticated this.isAuthenticated = this.store.pipe(select(isAuthenticated)); @@ -139,7 +143,7 @@ export class LogInPasswordComponent implements OnDestroy, OnInit { takeWhile(() => this.alive), filter((authenticated) => authenticated)) .subscribe(() => { - this.authService.redirectAfterLoginSuccess(true); // HARDCODED FOR DEV _ CHANGE IT + this.authService.redirectAfterLoginSuccess(this.authMethodModel.isStandalonePage); } );