From 2f80b3a980647672300f2b42ec5d1b7dea26a0ee Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 17 Apr 2024 20:55:27 +0800 Subject: [PATCH 1/4] Add AbpAuthenticationSessionStateViewComponent to logout from other tabs for MVC UI --- .../AbpAspNetCoreMvcUiThemeSharedModule.cs | 8 +++ ...AuthenticationSessionStateViewComponent.cs | 11 ++++ .../Default.cshtml | 61 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs index 109746e34f..c9069bd5e3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs @@ -3,8 +3,11 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Packages; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; +using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationSessionState; +using Volo.Abp.AspNetCore.Mvc.UI.Theming; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.Modularity; +using Volo.Abp.Ui.LayoutHooks; using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; @@ -30,6 +33,11 @@ public class AbpAspNetCoreMvcUiThemeSharedModule : AbpModule { options.FileSets.AddEmbedded("Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared"); }); + + Configure(options => + { + options.Add(LayoutHooks.Body.Last, typeof(AbpAuthenticationSessionStateViewComponent)); + }); Configure(options => { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs new file mode 100644 index 0000000000..ceb9a32b91 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationSessionState; + +public class AbpAuthenticationSessionStateViewComponent : AbpViewComponent +{ +public virtual IViewComponentResult Invoke() +{ + return View("~/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml"); +} +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml new file mode 100644 index 0000000000..8c07e6fccf --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml @@ -0,0 +1,61 @@ + \ No newline at end of file From 17934b9036c18245f0f4d083e6ceec550163713d Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 18 Apr 2024 14:13:29 +0800 Subject: [PATCH 2/4] Rename AbpAuthenticationSessionStateViewComponent to AbpAuthenticationStateViewComponent --- .../AbpAspNetCoreMvcUiThemeSharedModule.cs | 4 +- ...AuthenticationSessionStateViewComponent.cs | 11 ---- .../Default.cshtml | 61 ------------------- .../AbpAuthenticationStateViewComponent.cs | 11 ++++ .../AbpAuthenticationState/Default.cshtml | 48 +++++++++++++++ 5 files changed, 61 insertions(+), 74 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs index c9069bd5e3..5f4ef0d192 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs @@ -3,7 +3,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Packages; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; -using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationSessionState; +using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationState; using Volo.Abp.AspNetCore.Mvc.UI.Theming; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.Modularity; @@ -36,7 +36,7 @@ public class AbpAspNetCoreMvcUiThemeSharedModule : AbpModule Configure(options => { - options.Add(LayoutHooks.Body.Last, typeof(AbpAuthenticationSessionStateViewComponent)); + options.Add(LayoutHooks.Body.Last, typeof(AbpAuthenticationStateViewComponent)); }); Configure(options => diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs deleted file mode 100644 index ceb9a32b91..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/AbpAuthenticationSessionStateViewComponent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationSessionState; - -public class AbpAuthenticationSessionStateViewComponent : AbpViewComponent -{ -public virtual IViewComponentResult Invoke() -{ - return View("~/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml"); -} -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml deleted file mode 100644 index 8c07e6fccf..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationSessionState/Default.cshtml +++ /dev/null @@ -1,61 +0,0 @@ - \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs new file mode 100644 index 0000000000..f48c63b6d5 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationState; + +public class AbpAuthenticationStateViewComponent : AbpViewComponent +{ +public virtual IViewComponentResult Invoke() +{ + return View("~/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml"); +} +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml new file mode 100644 index 0000000000..f9112b1de7 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml @@ -0,0 +1,48 @@ + \ No newline at end of file From 684ab909502a3a3126c0389318cba1357c672bf1 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 18 Apr 2024 15:36:43 +0800 Subject: [PATCH 3/4] Add authentication-state-listener.js --- .../AbpAspNetCoreMvcUiThemeSharedModule.cs | 8 ---- .../SharedThemeGlobalScriptContributor.cs | 3 +- .../AbpAuthenticationStateViewComponent.cs | 11 ----- .../AbpAuthenticationState/Default.cshtml | 48 ------------------- .../authentication-state-listener.js | 30 ++++++++++++ 5 files changed, 32 insertions(+), 68 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs index 5f4ef0d192..b62d3f27ba 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs @@ -3,11 +3,8 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Packages; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; -using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationState; -using Volo.Abp.AspNetCore.Mvc.UI.Theming; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.Modularity; -using Volo.Abp.Ui.LayoutHooks; using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; @@ -34,11 +31,6 @@ public class AbpAspNetCoreMvcUiThemeSharedModule : AbpModule options.FileSets.AddEmbedded("Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared"); }); - Configure(options => - { - options.Add(LayoutHooks.Body.Last, typeof(AbpAuthenticationStateViewComponent)); - }); - Configure(options => { options diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs index 27f3760000..5d8c15ba40 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs @@ -49,7 +49,8 @@ public class SharedThemeGlobalScriptContributor : BundleContributor "/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js", "/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert2/abp-sweetalert2.js", "/libs/abp/aspnetcore-mvc-ui-theme-shared/toastr/abp-toastr.js", - "/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-extensions.js" + "/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-extensions.js", + "/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js" }); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs deleted file mode 100644 index f48c63b6d5..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/AbpAuthenticationStateViewComponent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpAuthenticationState; - -public class AbpAuthenticationStateViewComponent : AbpViewComponent -{ -public virtual IViewComponentResult Invoke() -{ - return View("~/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml"); -} -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml deleted file mode 100644 index f9112b1de7..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Shared/Components/AbpAuthenticationState/Default.cshtml +++ /dev/null @@ -1,48 +0,0 @@ - \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js new file mode 100644 index 0000000000..1b6ec69602 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js @@ -0,0 +1,30 @@ +(function () { + + const stateKey = 'authentication-state-id'; + + window.addEventListener('load', function () { + if (!abp || !abp.currentUser) { + return; + } + + if (!abp.currentUser.isAuthenticated){ + localStorage.removeItem(stateKey); + }else{ + localStorage.setItem(stateKey, abp.currentUser.id); + } + + window.addEventListener('storage', function (event) { + + if (event.key !== stateKey || event.oldValue === event.newValue) { + return; + } + + if(event.oldValue || !event.newValue) { + window.location.reload(); + }else{ + location.assign('/') + } + }); + }); + +}()); \ No newline at end of file From f9eb84cbc01cbacc1b0c9c0d252395225c49b3c1 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 18 Apr 2024 15:45:53 +0800 Subject: [PATCH 4/4] Update authentication-state-listener.js --- .../authentication-state-listener.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js index 1b6ec69602..848760f854 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js @@ -1,30 +1,30 @@ (function () { - + const stateKey = 'authentication-state-id'; window.addEventListener('load', function () { if (!abp || !abp.currentUser) { return; } - - if (!abp.currentUser.isAuthenticated){ + + if (!abp.currentUser.isAuthenticated) { localStorage.removeItem(stateKey); - }else{ + } else { localStorage.setItem(stateKey, abp.currentUser.id); } window.addEventListener('storage', function (event) { - + if (event.key !== stateKey || event.oldValue === event.newValue) { return; } - - if(event.oldValue || !event.newValue) { + + if (event.oldValue || !event.newValue) { window.location.reload(); - }else{ + } else { location.assign('/') } }); }); - + }()); \ No newline at end of file