Fix display order of authentication methods

This commit is contained in:
Alexandre Vryghem
2023-08-02 00:00:37 +02:00
parent ca864379c8
commit 71cf66ecf4
20 changed files with 107 additions and 173 deletions

View File

@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { select, Store } from '@ngrx/store';
import { AuthMethod } from '../../core/auth/models/auth.method';
@@ -8,11 +8,8 @@ import {
isAuthenticated,
isAuthenticationLoading
} from '../../core/auth/selectors';
import { getForgotPasswordRoute, getRegisterRoute } from '../../app-routing-paths';
import { hasValue } from '../empty.util';
import { AuthService } from '../../core/auth/auth.service';
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { CoreState } from '../../core/core-state.model';
/**
@@ -22,7 +19,8 @@ import { CoreState } from '../../core/core-state.model';
@Component({
selector: 'ds-log-in',
templateUrl: './log-in.component.html',
styleUrls: ['./log-in.component.scss']
styleUrls: ['./log-in.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LogInComponent implements OnInit {
@@ -50,14 +48,9 @@ export class LogInComponent implements OnInit {
*/
public loading: Observable<boolean>;
/**
* Whether or not the current user (or anonymous) is authorized to register an account
*/
canRegister$: Observable<boolean>;
constructor(private store: Store<CoreState>,
private authService: AuthService,
private authorizationService: AuthorizationDataService) {
) {
}
ngOnInit(): void {
@@ -78,15 +71,18 @@ export class LogInComponent implements OnInit {
this.authService.clearRedirectUrl();
}
});
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);
}
getRegisterRoute() {
return getRegisterRoute();
}
getForgotRoute() {
return getForgotPasswordRoute();
/**
* Returns an ordered list of {@link AuthMethod}s based on their position.
*
* @param authMethods The {@link AuthMethod}s to sort
*/
getOrderedAuthMethods(authMethods: AuthMethod[] | null): AuthMethod[] {
if (hasValue(authMethods)) {
return [...authMethods].sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position);
} else {
return [];
}
}
}