11import { ChangeDetectionStrategy , Component , Input , OnDestroy , OnInit } from '@angular/core' ;
2- import { Observable , Subscription , combineLatest } from 'rxjs' ;
32import { filter , map , shareReplay } from 'rxjs/operators' ;
43import { select , Store } from '@ngrx/store' ;
5- import uniqBy from 'lodash/uniqBy' ;
6-
74import { AuthMethod } from '../../core/auth/models/auth.method' ;
85import {
96 getAuthenticationError ,
@@ -19,6 +16,10 @@ import { rendersAuthMethodType } from './methods/log-in.methods-decorator';
1916import { AuthMethodType } from '../../core/auth/models/auth.method-type' ;
2017import { FeatureID } from '../../core/data/feature-authorization/feature-id' ;
2118import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
19+ import { ActivatedRoute } from '@angular/router' ;
20+ import uniqBy from 'lodash/uniqBy' ;
21+ import { environment } from '../../../environments/environment' ;
22+ import { combineLatestWith , Observable , Subscription } from 'rxjs' ;
2223
2324@Component ( {
2425 selector : 'ds-log-in' ,
@@ -84,19 +85,20 @@ export class LogInComponent implements OnInit, OnDestroy {
8485
8586 constructor ( private store : Store < CoreState > ,
8687 private authService : AuthService ,
88+ private route : ActivatedRoute ,
8789 protected authorizationService : AuthorizationDataService
8890 ) {
8991 }
9092
9193 ngOnInit ( ) : void {
9294 this . authMethods = this . store . pipe (
9395 select ( getAuthenticationMethods ) ,
94- map ( ( methods : AuthMethod [ ] ) => methods
95- // ignore the given auth method if it should be excluded
96- . filter ( ( authMethod : AuthMethod ) => authMethod . authMethodType !== this . excludedAuthMethod )
97- . filter ( ( authMethod : AuthMethod ) => rendersAuthMethodType ( authMethod . authMethodType ) !== undefined )
98- . sort ( ( method1 : AuthMethod , method2 : AuthMethod ) => method1 . position - method2 . position ) ,
99- ) ,
96+ combineLatestWith (
97+ this . route . data . pipe (
98+ filter ( routeData => ! ! routeData ) ,
99+ map ( data => data . isBackDoor ) ,
100+ ) ) ,
101+ map ( ( [ methods , isBackdoor ] ) => this . filterAndSortAuthMethods ( methods , isBackdoor , environment . auth . disableStandardLogin ) ) ,
100102 // ignore the ip authentication method when it's returned by the backend
101103 map ( ( authMethods : AuthMethod [ ] ) => uniqBy ( authMethods . filter ( a => a . authMethodType !== AuthMethodType . Ip ) , 'authMethodType' ) )
102104 ) ;
@@ -117,12 +119,30 @@ export class LogInComponent implements OnInit, OnDestroy {
117119 this . canRegister$ = this . authorizationService . isAuthorized ( FeatureID . EPersonRegistration ) ;
118120
119121 this . canForgot$ = this . authorizationService . isAuthorized ( FeatureID . EPersonForgotPassword ) . pipe ( shareReplay ( 1 ) ) ;
120- this . canShowDivider$ =
121- combineLatest ( [ this . canRegister$ , this . canForgot$ ] )
122- . pipe (
123- map ( ( [ canRegister , canForgot ] ) => canRegister || canForgot ) ,
124- filter ( Boolean )
125- ) ;
122+ this . canShowDivider$ = this . canRegister$ . pipe (
123+ combineLatestWith ( this . canForgot$ ) ,
124+ map ( ( [ canRegister , canForgot ] ) => canRegister || canForgot ) ,
125+ filter ( Boolean )
126+ ) ;
127+ }
128+
129+ filterAndSortAuthMethods ( authMethods : AuthMethod [ ] , isBackdoor : boolean , isStandardLoginDisabled = false ) : AuthMethod [ ] {
130+ return authMethods . filter ( ( authMethod : AuthMethod ) => {
131+ const methodComparison = ( authM ) => {
132+ if ( isBackdoor ) {
133+ return authM . authMethodType === AuthMethodType . Password ;
134+ }
135+ if ( isStandardLoginDisabled ) {
136+ return authM . authMethodType !== AuthMethodType . Password ;
137+ }
138+ return true ;
139+
140+ } ;
141+ return methodComparison ( authMethod ) &&
142+ authMethod . authMethodType !== this . excludedAuthMethod &&
143+ rendersAuthMethodType ( authMethod . authMethodType ) !== undefined ;
144+ } ,
145+ ) . sort ( ( method1 : AuthMethod , method2 : AuthMethod ) => method1 . position - method2 . position ) ;
126146 }
127147
128148 getRegisterRoute ( ) {
0 commit comments