Redirect on log out #1225 Fix

This commit is contained in:
Leigh Pointer 2021-04-18 16:58:58 +02:00
parent 8dac6fab54
commit 1e7e2c8848

View File

@ -3,17 +3,19 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Oqtane.Providers; using Oqtane.Providers;
using Oqtane.Security;
using Oqtane.Services; using Oqtane.Services;
using Oqtane.Shared;
using Oqtane.UI; using Oqtane.UI;
namespace Oqtane.Themes.Controls namespace Oqtane.Themes.Controls
{ {
public class LoginBase : ThemeControlBase public class LoginBase : ThemeControlBase
{ {
[Inject] public NavigationManager NavigationManager {get;set;} [Inject] public NavigationManager NavigationManager { get; set; }
[Inject]public IUserService UserService {get;set;} [Inject] public IUserService UserService { get; set; }
[Inject]public IJSRuntime jsRuntime {get;set;} [Inject] public IJSRuntime jsRuntime { get; set; }
[Inject]public IServiceProvider ServiceProvider {get;set;} [Inject] public IServiceProvider ServiceProvider { get; set; }
protected void LoginUser() protected void LoginUser()
{ {
@ -29,13 +31,14 @@ namespace Oqtane.Themes.Controls
{ {
await UserService.LogoutUserAsync(PageState.User); await UserService.LogoutUserAsync(PageState.User);
PageState.User = null; PageState.User = null;
bool authorizedtoviewpage = UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, PageState.Page.Permissions);
if (PageState.Runtime == Oqtane.Shared.Runtime.Server) if (PageState.Runtime == Oqtane.Shared.Runtime.Server)
{ {
// server-side Blazor // server-side Blazor
var interop = new Interop(jsRuntime); var interop = new Interop(jsRuntime);
string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken"); string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken");
var fields = new { __RequestVerificationToken = antiforgerytoken, returnurl = (PageState.Alias.Path + "/" + PageState.Page.Path) }; var fields = new { __RequestVerificationToken = antiforgerytoken, returnurl = !authorizedtoviewpage ? PageState.Alias.Path : PageState.Alias.Path + "/" + PageState.Page.Path };
await interop.SubmitForm($"/{PageState.Alias.AliasId}/pages/logout/", fields); await interop.SubmitForm($"/{PageState.Alias.AliasId}/pages/logout/", fields);
} }
else else
@ -43,7 +46,7 @@ namespace Oqtane.Themes.Controls
// client-side Blazor // client-side Blazor
var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider)); var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
authstateprovider.NotifyAuthenticationChanged(); authstateprovider.NotifyAuthenticationChanged();
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "reload")); NavigationManager.NavigateTo(NavigateUrl(!authorizedtoviewpage ? PageState.Alias.Path : PageState.Page.Path, "reload"));
} }
} }
} }