Browse Source

Rename AbpAuthenticationSessionState to AbpAuthenticationState

pull/19563/head
liangshiwei 2 years ago
parent
commit
5199f9a049
  1. 2
      framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalScriptContributor.cs
  2. 2
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/AbpAspNetCoreComponentsWebThemingModule.cs
  3. 14
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Security/AbpAuthenticationState.cs
  4. 13
      framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/authentication-state-listener.js
  5. 2
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ComponentsComponentsBundleContributor.cs
  6. 2
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Client/wwwroot/global.js
  7. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/global.js
  8. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Client/wwwroot/global.js
  9. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Tiered.Client/wwwroot/global.js
  10. 4
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/App.razor
  11. 2
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host.Client/wwwroot/global.js
  12. 4
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/App.razor

2
framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalScriptContributor.cs

@ -15,6 +15,6 @@ public class BlazorGlobalScriptContributor : BundleContributor
context.Files.AddIfNotContains("/_framework/blazor.server.js");
}
context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js");
context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/authentication-session-state-listener.js");
context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/authentication-state-listener.js");
}
}

2
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/AbpAspNetCoreComponentsWebThemingModule.cs

@ -15,7 +15,7 @@ public class AbpAspNetCoreComponentsWebThemingModule : AbpModule
{
Configure<AbpDynamicLayoutComponentOptions>(options =>
{
options.Components.Add(typeof(AbpAuthenticationSessionState), null);
options.Components.Add(typeof(AbpAuthenticationState), null);
});
}
}

14
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Security/AbpAuthenticationSessionState.cs → framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Security/AbpAuthenticationState.cs

@ -7,9 +7,9 @@ using Volo.Abp.Users;
namespace Volo.Abp.AspNetCore.Components.Web.Security;
public class AbpAuthenticationSessionState : ComponentBase
public class AbpAuthenticationState : ComponentBase
{
private const string SessionKey = "authentication-session-id";
private const string StateKey = "authentication-state-id";
[Inject]
protected ILocalStorageService LocalStorage { get; set; } = default!;
@ -49,17 +49,11 @@ public class AbpAuthenticationSessionState : ComponentBase
protected virtual async Task SetAuthenticationStateAsync()
{
var sessionId = await LocalStorage.GetItemAsync(SessionKey);
if (sessionId.IsNullOrWhiteSpace())
{
sessionId = CurrentUser.FindSessionId() ?? Guid.NewGuid().ToString();
}
await LocalStorage.SetItemAsync(SessionKey, sessionId);
await LocalStorage.SetItemAsync(StateKey, CurrentUser.GetId().ToString());
}
protected virtual async Task ClearAuthenticationStateAsync()
{
await LocalStorage.RemoveItemAsync(SessionKey);
await LocalStorage.RemoveItemAsync(StateKey);
}
}

13
framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/authentication-session-state-listener.js → framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/authentication-state-listener.js

@ -1,22 +1,21 @@
(function () {
const sessionKey = 'authentication-session-id';
const stateKey = 'authentication-state-id';
window.addEventListener('storage', function (event) {
console.log(event);
if (event.key !== sessionKey) {
if (event.key !== stateKey) {
return;
}
var previousSessionId = event.oldValue
var sessionId = event.newValue;
var previousState = event.oldValue
var state = event.newValue;
if(previousSessionId === sessionId) {
if(previousState === state) {
return;
}
if(previousSessionId || !sessionId) {
if(previousState || !state) {
abp.utils.removeOidcUser();
window.location.reload();
return;

2
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ComponentsComponentsBundleContributor.cs

@ -10,7 +10,7 @@ public class ComponentsComponentsBundleContributor : IBundleContributor
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js");
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/lang-utils.js");
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/lang-utils.js");
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/authentication-session-state-listener.js");
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/authentication-state-listener.js");
}
public void AddStyles(BundleContext context)

2
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Client/wwwroot/global.js

@ -5,7 +5,7 @@ var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.domReady=function(n){doc
var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.utils.updateHTMLDirAndLangFromLocalStorage=function(){var i=JSON.parse(localStorage.getItem("Abp.IsRtl")),n=document.getElementsByTagName("html")[0],t;n&&(t=localStorage.getItem("Abp.SelectedLanguage"),t&&n.setAttribute("lang",t),i&&n.setAttribute("dir","rtl"))};abp.utils.updateHTMLDirAndLangFromLocalStorage()})();
(function(){const n="authentication-session-id";window.addEventListener("storage",function(t){if(console.log(t),t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
(function(){const n="authentication-state-id";window.addEventListener("storage",function(t){if(t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
/*!
* Bootstrap v5.1.3 (https://getbootstrap.com/)

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/global.js

@ -5,7 +5,7 @@ var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.domReady=function(n){doc
var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.utils.updateHTMLDirAndLangFromLocalStorage=function(){var i=JSON.parse(localStorage.getItem("Abp.IsRtl")),n=document.getElementsByTagName("html")[0],t;n&&(t=localStorage.getItem("Abp.SelectedLanguage"),t&&n.setAttribute("lang",t),i&&n.setAttribute("dir","rtl"))};abp.utils.updateHTMLDirAndLangFromLocalStorage()})();
(function(){const n="authentication-session-id";window.addEventListener("storage",function(t){if(console.log(t),t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
(function(){const n="authentication-state-id";window.addEventListener("storage",function(t){if(t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
/*!
* Bootstrap v5.1.3 (https://getbootstrap.com/)

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Client/wwwroot/global.js

@ -5,7 +5,7 @@ var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.domReady=function(n){doc
var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.utils.updateHTMLDirAndLangFromLocalStorage=function(){var i=JSON.parse(localStorage.getItem("Abp.IsRtl")),n=document.getElementsByTagName("html")[0],t;n&&(t=localStorage.getItem("Abp.SelectedLanguage"),t&&n.setAttribute("lang",t),i&&n.setAttribute("dir","rtl"))};abp.utils.updateHTMLDirAndLangFromLocalStorage()})();
(function(){const n="authentication-session-id";window.addEventListener("storage",function(t){if(console.log(t),t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
(function(){const n="authentication-state-id";window.addEventListener("storage",function(t){if(t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
/*!
* Bootstrap v5.1.3 (https://getbootstrap.com/)

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Tiered.Client/wwwroot/global.js

@ -5,7 +5,7 @@ var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.domReady=function(n){doc
var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.utils.updateHTMLDirAndLangFromLocalStorage=function(){var i=JSON.parse(localStorage.getItem("Abp.IsRtl")),n=document.getElementsByTagName("html")[0],t;n&&(t=localStorage.getItem("Abp.SelectedLanguage"),t&&n.setAttribute("lang",t),i&&n.setAttribute("dir","rtl"))};abp.utils.updateHTMLDirAndLangFromLocalStorage()})();
(function(){const n="authentication-session-id";window.addEventListener("storage",function(t){if(console.log(t),t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
(function(){const n="authentication-state-id";window.addEventListener("storage",function(t){if(t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
/*!
* Bootstrap v5.1.3 (https://getbootstrap.com/)

4
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/App.razor

@ -8,7 +8,7 @@
<base href="/" />
<!--ABP:Styles-->
<link href="global.css?_v=638489663522459204" rel="stylesheet"/>
<link href="global.css?_v=638490472437960190" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles-->
<link href="MyCompanyName.MyProjectName.Blazor.Client.styles.css" rel="stylesheet"/>
@ -36,7 +36,7 @@
</div>
<!--ABP:Scripts-->
<script src="global.js?_v=638489663523674702"></script>
<script src="global.js?_v=638490472439212479"></script>
<!--/ABP:Scripts-->
<!-- <TEMPLATE-REMOVE IF-NOT='PWA'> -->

2
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host.Client/wwwroot/global.js

@ -5,5 +5,5 @@ var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.domReady=function(n){doc
var abp=abp||{};(function(){abp.utils=abp.utils||{};abp.utils.updateHTMLDirAndLangFromLocalStorage=function(){var i=JSON.parse(localStorage.getItem("Abp.IsRtl")),n=document.getElementsByTagName("html")[0],t;n&&(t=localStorage.getItem("Abp.SelectedLanguage"),t&&n.setAttribute("lang",t),i&&n.setAttribute("dir","rtl"))};abp.utils.updateHTMLDirAndLangFromLocalStorage()})();
(function(){const n="authentication-session-id";window.addEventListener("storage",function(t){if(console.log(t),t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();
(function(){const n="authentication-state-id";window.addEventListener("storage",function(t){if(t.key===n){var i=t.oldValue,r=t.newValue;if(i!==r){if(i||!r){abp.utils.removeOidcUser();window.location.reload();return}location.assign("/")}}})})();

4
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/App.razor

@ -8,7 +8,7 @@
<base href="/" />
<!--ABP:Styles-->
<link href="global.css?_v=638489664222343444" rel="stylesheet"/>
<link href="global.css?_v=638490473180922552" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles-->
<link href="MyCompanyName.MyProjectName.Blazor.Host.Client.styles.css" rel="stylesheet"/>
@ -30,7 +30,7 @@
</div>
<!--ABP:Scripts-->
<script src="global.js?_v=638489664222929221"></script>
<script src="global.js?_v=638490473181552035"></script>
<!--/ABP:Scripts-->
</body>

Loading…
Cancel
Save