Allow option to re-direct on logout action

- Add logout configuration
- Change auth.service.ts to re-direct instead of posting depending on configuration
This commit is contained in:
Clemente Raposo 2022-08-09 15:20:57 +01:00
parent 606d1540e3
commit 3cd6efcc3f
5 changed files with 34 additions and 5 deletions

View file

@ -56,6 +56,7 @@ services:
$subpanelTopActions: '%module.subpanel.top_actions%'
$subpanelTopButtons: '%module.subpanel.top_buttons%'
$ldapAutoCreateExtraFieldsMap: '%ldap.autocreate.extra_fields_map%'
$logoutConfig: '%auth.logout%'
_instanceof:
App\Process\Service\ProcessHandlerInterface:
tags: [ 'app.process.handler' ]
@ -296,6 +297,8 @@ services:
alias: App\SystemConfig\Service\SystemConfigProviderInterface
public: true
Symfony\Component\Security\Http\Logout\LogoutUrlGenerator: '@security.logout_url_generator'
App\UserPreferences\Service\UserPreferencesProviderInterface: '@App\UserPreferences\LegacyHandler\UserPreferenceHandler'
App\ViewDefinitions\Service\ViewDefinitionsProviderInterface: '@App\ViewDefinitions\LegacyHandler\ViewDefinitionsHandler'
App\Engine\Service\FolderSync\FolderComparatorInterface: '@App\Engine\Service\FolderSync\FolderComparator'

View file

@ -0,0 +1,4 @@
parameters:
auth.logout:
path: "%auth.logout.path%"
redirect: "%auth.logout.redirect%"

View file

@ -29,3 +29,4 @@ parameters:
recordview_actions_limits: true
ui: true
extensions: true
logout: true

View file

@ -29,7 +29,7 @@ import {Router} from '@angular/router';
import {HttpClient, HttpErrorResponse, HttpHeaders, HttpParams} from '@angular/common/http';
import {BehaviorSubject, Observable, Subscription, throwError} from 'rxjs';
import {catchError, distinctUntilChanged, filter, finalize, take} from 'rxjs/operators';
import {isEmptyString, User} from 'common';
import {isEmptyString, isTrue, User} from 'common';
import {MessageService} from '../message/message.service';
import {StateManager} from '../../store/state-manager';
import {LanguageStore} from '../../store/language/language.store';
@ -148,21 +148,23 @@ export class AuthService {
public logout(messageKey = 'LBL_LOGOUT_SUCCESS', redirect = true): void {
this.appStateStore.updateLoading('logout', true, false);
let logoutUrl = 'logout';
const logoutConfig = this.configs.getConfigValue('logout') ?? [];
let logoutUrl = (logoutConfig?.path ?? 'logout') as string;
const redirectLogout = isTrue(logoutConfig?.redirect ?? false);
logoutUrl = this.baseRoute.calculateRoute(logoutUrl);
const body = new HttpParams();
const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
if (this.appStateStore.getActiveRequests() < 1) {
this.callLogout(logoutUrl, body, headers, redirect, messageKey);
this.callLogout(logoutUrl, body, headers, redirect, messageKey, redirectLogout);
} else {
this.appStateStore.activeRequests$.pipe(
filter(value => value < 1),
take(1)
).subscribe(
() => {
this.callLogout(logoutUrl, body, headers, redirect, messageKey);
this.callLogout(logoutUrl, body, headers, redirect, messageKey, redirectLogout);
}
)
}
@ -175,10 +177,23 @@ export class AuthService {
* @param headers
* @param redirect
* @param messageKey
* @param redirectLogout
* @protected
*/
protected callLogout(logoutUrl: string, body: HttpParams, headers: HttpHeaders, redirect: boolean, messageKey: string) {
protected callLogout(
logoutUrl: string,
body: HttpParams,
headers: HttpHeaders,
redirect: boolean,
messageKey: string,
redirectLogout: boolean
) {
this.resetState();
if (redirectLogout) {
window.location.href = logoutUrl;
return;
}
this.http.post(logoutUrl, body.toString(), {headers, responseType: 'text'})
.pipe(
take(1),

View file

@ -100,6 +100,7 @@ class SystemConfigHandler extends LegacyHandler implements SystemConfigProviderI
* @param array $listViewLineActionsLimits
* @param array $uiConfigs
* @param array $extensions
* @param array $logoutConfig
* @param SessionInterface $session
* @param NavigationProviderInterface $navigation
*/
@ -126,6 +127,7 @@ class SystemConfigHandler extends LegacyHandler implements SystemConfigProviderI
array $listViewLineActionsLimits,
array $uiConfigs,
array $extensions,
array $logoutConfig,
SessionInterface $session,
NavigationProviderInterface $navigation
) {
@ -152,6 +154,10 @@ class SystemConfigHandler extends LegacyHandler implements SystemConfigProviderI
$this->injectedSystemConfigs['listview_line_actions_limits'] = $listViewLineActionsLimits;
$this->injectedSystemConfigs['ui'] = $uiConfigs;
$this->injectedSystemConfigs['extensions'] = $extensions;
$logoutConfig = $logoutConfig ?? [];
$this->injectedSystemConfigs['logout'] = $logoutConfig;
$this->mappers = $mappers;
$this->systemConfigKeyMap = $systemConfigKeyMap;
$this->currencyHandler = $currencyHandler;