Browse Source

Introduce ApplicationConfigurationChangedService.

Synchronized abpframework/abp #15649
pull/19/head
Jadyn 3 years ago
parent
commit
556002e71d
  1. 11
      modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/MainMenu.razor.cs
  2. 12
      modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/Themes/AntDesignTheme/NavToolbar.razor.cs
  3. 3
      modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/AntDesignThemeToolbarContributor.cs
  4. 16
      modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Pages/Authentication.razor
  5. 26
      modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Themes/AntDesignTheme/LoginDisplay.razor.cs

11
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;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Components.Web.Security;
using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation;
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesignTheme; namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesignTheme;
@ -17,7 +18,7 @@ public partial class MainMenu : IDisposable
protected IMenuManager MenuManager { get; set; } protected IMenuManager MenuManager { get; set; }
[Inject] [Inject]
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } protected ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; }
[Parameter] [Parameter]
public MenuPlacement Placement { get; set; } public MenuPlacement Placement { get; set; }
@ -31,15 +32,15 @@ public partial class MainMenu : IDisposable
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await GetMenuAsync(); await GetMenuAsync();
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged;
} }
private async Task GetMenuAsync() private async Task GetMenuAsync()
{ {
Menu = await MenuManager.GetMainMenuAsync(); Menu = await MenuManager.GetMainMenuAsync();
} }
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task) private async void ApplicationConfigurationChanged()
{ {
await GetMenuAsync(); await GetMenuAsync();
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
@ -47,6 +48,6 @@ public partial class MainMenu : IDisposable
public void Dispose() public void Dispose()
{ {
AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged; ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged;
} }
} }

12
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 System.Threading.Tasks;
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars;
using Microsoft.AspNetCore.Components; 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; namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesignTheme;
public partial class NavToolbar: IDisposable public partial class NavToolbar : IDisposable
{ {
[Inject] [Inject]
private IToolbarManager ToolbarManager { get; set; } private IToolbarManager ToolbarManager { get; set; }
[Inject] [Inject]
private AuthenticationStateProvider AuthenticationStateProvider { get; set; } private ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; }
private List<RenderFragment> ToolbarItemRenders { get; set; } = new(); private List<RenderFragment> ToolbarItemRenders { get; set; } = new();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await GetToolbarItemRendersAsync(); await GetToolbarItemRendersAsync();
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged;
} }
private async Task GetToolbarItemRendersAsync() private async Task GetToolbarItemRendersAsync()
@ -40,7 +40,7 @@ public partial class NavToolbar: IDisposable
} }
} }
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task) private async void ApplicationConfigurationChanged()
{ {
await GetToolbarItemRendersAsync(); await GetToolbarItemRendersAsync();
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
@ -48,6 +48,6 @@ public partial class NavToolbar: IDisposable
public void Dispose() public void Dispose()
{ {
AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged; ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged;
} }
} }

3
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))); 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 var authenticationStateProvider = context.ServiceProvider
.GetRequiredService<AuthenticationStateProvider>(); .GetService<AuthenticationStateProvider>();
if (authenticationStateProvider != null) if (authenticationStateProvider != null)
{ {

16
modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Pages/Authentication.razor

@ -1,7 +1,21 @@
@page "/authentication/{action}" @page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication @using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" /> @using Volo.Abp.AspNetCore.Components.Web.Security
@using Volo.Abp.AspNetCore.Components.WebAssembly
<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded="OnLogInSucceeded" OnLogOutSucceeded="OnLogOutSucceeded" />
@inject WebAssemblyCachedApplicationConfigurationClient WebAssemblyCachedApplicationConfigurationClient
@code{ @code{
[Parameter] public string Action { get; set; } [Parameter] public string Action { get; set; }
private async Task OnLogInSucceeded(RemoteAuthenticationState state)
{
await WebAssemblyCachedApplicationConfigurationClient.InitializeAsync();
}
private async Task OnLogOutSucceeded(RemoteAuthenticationState state)
{
await WebAssemblyCachedApplicationConfigurationClient.InitializeAsync();
}
} }

26
modules/AntDesignTheme/Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme/Themes/AntDesignTheme/LoginDisplay.razor.cs

@ -1,11 +1,10 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication; using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Volo.Abp.AspNetCore.Components.Web.Security;
using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation;
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Themes.AntDesignTheme; namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Themes.AntDesignTheme;
@ -16,10 +15,7 @@ public partial class LoginDisplay : IDisposable
protected IMenuManager MenuManager { get; set; } protected IMenuManager MenuManager { get; set; }
[Inject] [Inject]
public AuthenticationStateProvider AuthenticationStateProvider { get; set; } protected ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; }
[CanBeNull]
protected SignOutSessionStateManager SignOutManager;
protected ApplicationMenu Menu { get; set; } protected ApplicationMenu Menu { get; set; }
@ -29,10 +25,7 @@ public partial class LoginDisplay : IDisposable
Navigation.LocationChanged += OnLocationChanged; Navigation.LocationChanged += OnLocationChanged;
LazyGetService(ref SignOutManager); ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged;
AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged;
} }
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e) protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e)
@ -40,7 +33,7 @@ public partial class LoginDisplay : IDisposable
InvokeAsync(StateHasChanged); InvokeAsync(StateHasChanged);
} }
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task) private async void ApplicationConfigurationChanged()
{ {
Menu = await MenuManager.GetAsync(StandardMenus.User); Menu = await MenuManager.GetAsync(StandardMenus.User);
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
@ -49,8 +42,7 @@ public partial class LoginDisplay : IDisposable
public void Dispose() public void Dispose()
{ {
Navigation.LocationChanged -= OnLocationChanged; Navigation.LocationChanged -= OnLocationChanged;
AuthenticationStateProvider.AuthenticationStateChanged -= ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged;
AuthenticationStateProviderOnAuthenticationStateChanged;
} }
private async Task NavigateToAsync(string uri, string target = null) 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) Navigation.NavigateToLogout("authentication/logout");
{
await SignOutManager.SetSignOutState();
await NavigateToAsync("authentication/logout");
}
} }
} }

Loading…
Cancel
Save