From 556002e71d9a2bb3f354553d930146486633ad5e Mon Sep 17 00:00:00 2001 From: Jadyn Date: Fri, 27 Oct 2023 01:01:42 +0800 Subject: [PATCH] Introduce ApplicationConfigurationChangedService. Synchronized abpframework/abp #15649 --- .../Themes/AntDesignTheme/MainMenu.razor.cs | 11 ++++---- .../Themes/AntDesignTheme/NavToolbar.razor.cs | 12 ++++----- .../AntDesignThemeToolbarContributor.cs | 3 ++- .../Pages/Authentication.razor | 16 +++++++++++- .../AntDesignTheme/LoginDisplay.razor.cs | 26 +++++-------------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/MainMenu.razor.cs b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/MainMenu.razor.cs index b115dd9..e1d8ee1 100644 --- a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/MainMenu.razor.cs +++ b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/MainMenu.razor.cs @@ -5,6 +5,7 @@ using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Settings; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Components.Web.Security; using Volo.Abp.UI.Navigation; namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesignTheme; @@ -17,7 +18,7 @@ public partial class MainMenu : IDisposable protected IMenuManager MenuManager { get; set; } [Inject] - protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } + protected ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; } [Parameter] public MenuPlacement Placement { get; set; } @@ -31,15 +32,15 @@ public partial class MainMenu : IDisposable protected override async Task OnInitializedAsync() { await GetMenuAsync(); - AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; + ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged; } private async Task GetMenuAsync() { Menu = await MenuManager.GetMainMenuAsync(); } - - private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task task) + + private async void ApplicationConfigurationChanged() { await GetMenuAsync(); await InvokeAsync(StateHasChanged); @@ -47,6 +48,6 @@ public partial class MainMenu : IDisposable public void Dispose() { - AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged; + ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged; } } diff --git a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/NavToolbar.razor.cs b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/NavToolbar.razor.cs index 4407dce..7c99191 100644 --- a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/NavToolbar.razor.cs +++ b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/NavToolbar.razor.cs @@ -3,24 +3,24 @@ using System.Collections.Generic; using System.Threading.Tasks; using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Authorization; +using Volo.Abp.AspNetCore.Components.Web.Security; namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesignTheme; -public partial class NavToolbar: IDisposable +public partial class NavToolbar : IDisposable { [Inject] private IToolbarManager ToolbarManager { get; set; } [Inject] - private AuthenticationStateProvider AuthenticationStateProvider { get; set; } + private ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; } private List ToolbarItemRenders { get; set; } = new(); protected override async Task OnInitializedAsync() { await GetToolbarItemRendersAsync(); - AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; + ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged; } private async Task GetToolbarItemRendersAsync() @@ -40,7 +40,7 @@ public partial class NavToolbar: IDisposable } } - private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task task) + private async void ApplicationConfigurationChanged() { await GetToolbarItemRendersAsync(); await InvokeAsync(StateHasChanged); @@ -48,6 +48,6 @@ public partial class NavToolbar: IDisposable public void Dispose() { - AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged; + ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged; } } diff --git a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/AntDesignThemeToolbarContributor.cs b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/AntDesignThemeToolbarContributor.cs index 3891372..18ca082 100644 --- a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/AntDesignThemeToolbarContributor.cs +++ b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/AntDesignThemeToolbarContributor.cs @@ -14,8 +14,9 @@ public class AntDesignThemeToolbarContributor: IToolbarContributor { context.Toolbar.Items.Add(new ToolbarItem(typeof(LanguageSwitch))); + //TODO: Can we find a different way to understand if authentication was configured or not? var authenticationStateProvider = context.ServiceProvider - .GetRequiredService(); + .GetService(); if (authenticationStateProvider != null) { diff --git a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Pages/Authentication.razor b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Pages/Authentication.razor index e237cea..287a267 100644 --- a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Pages/Authentication.razor +++ b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Pages/Authentication.razor @@ -1,7 +1,21 @@ @page "/authentication/{action}" @using Microsoft.AspNetCore.Components.WebAssembly.Authentication - +@using Volo.Abp.AspNetCore.Components.Web.Security +@using Volo.Abp.AspNetCore.Components.WebAssembly + +@inject WebAssemblyCachedApplicationConfigurationClient WebAssemblyCachedApplicationConfigurationClient @code{ [Parameter] public string Action { get; set; } + + + private async Task OnLogInSucceeded(RemoteAuthenticationState state) + { + await WebAssemblyCachedApplicationConfigurationClient.InitializeAsync(); + } + + private async Task OnLogOutSucceeded(RemoteAuthenticationState state) + { + await WebAssemblyCachedApplicationConfigurationClient.InitializeAsync(); + } } diff --git a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Themes/AntDesignTheme/LoginDisplay.razor.cs b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Themes/AntDesignTheme/LoginDisplay.razor.cs index e1e6487..922f631 100644 --- a/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Themes/AntDesignTheme/LoginDisplay.razor.cs +++ b/modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Themes/AntDesignTheme/LoginDisplay.razor.cs @@ -1,11 +1,10 @@ using System; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.JSInterop; +using Volo.Abp.AspNetCore.Components.Web.Security; using Volo.Abp.UI.Navigation; namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Themes.AntDesignTheme; @@ -16,10 +15,7 @@ public partial class LoginDisplay : IDisposable protected IMenuManager MenuManager { get; set; } [Inject] - public AuthenticationStateProvider AuthenticationStateProvider { get; set; } - - [CanBeNull] - protected SignOutSessionStateManager SignOutManager; + protected ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; } protected ApplicationMenu Menu { get; set; } @@ -29,10 +25,7 @@ public partial class LoginDisplay : IDisposable Navigation.LocationChanged += OnLocationChanged; - LazyGetService(ref SignOutManager); - - AuthenticationStateProvider.AuthenticationStateChanged += - AuthenticationStateProviderOnAuthenticationStateChanged; + ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged; } protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e) @@ -40,7 +33,7 @@ public partial class LoginDisplay : IDisposable InvokeAsync(StateHasChanged); } - private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task task) + private async void ApplicationConfigurationChanged() { Menu = await MenuManager.GetAsync(StandardMenus.User); await InvokeAsync(StateHasChanged); @@ -49,8 +42,7 @@ public partial class LoginDisplay : IDisposable public void Dispose() { Navigation.LocationChanged -= OnLocationChanged; - AuthenticationStateProvider.AuthenticationStateChanged -= - AuthenticationStateProviderOnAuthenticationStateChanged; + ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged; } private async Task NavigateToAsync(string uri, string target = null) @@ -65,12 +57,8 @@ public partial class LoginDisplay : IDisposable } } - private async Task BeginSignOut() + private void BeginSignOut() { - if (SignOutManager != null) - { - await SignOutManager.SetSignOutState(); - await NavigateToAsync("authentication/logout"); - } + Navigation.NavigateToLogout("authentication/logout"); } }