mirror of https://github.com/abpframework/abp.git
5 changed files with 32 additions and 68 deletions
@ -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"); |
|||
} |
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
<script type="text/javascript"> |
|||
(function () { |
|||
const stateKey = 'authentication-state-id'; |
|||
|
|||
if (!abp || !abp.currentUser){ |
|||
return; |
|||
} |
|||
|
|||
abp.authenticationStateValidator = { |
|||
init: function () { |
|||
this.checkAuthenticationState(); |
|||
this.setAuthenticationState() |
|||
}, |
|||
setAuthenticationState: function () { |
|||
if (!abp.currentUser.isAuthenticated){ |
|||
localStorage.removeItem(stateKey); |
|||
return; |
|||
} |
|||
localStorage.setItem(stateKey, abp.currentUser.id); |
|||
}, |
|||
checkAuthenticationState: function () { |
|||
window.addEventListener('storage', function (event) { |
|||
|
|||
if (event.key !== stateKey) { |
|||
return; |
|||
} |
|||
|
|||
var previousState = event.oldValue |
|||
var state = event.newValue; |
|||
|
|||
if(previousState === state) { |
|||
return; |
|||
} |
|||
|
|||
if(previousState || !state) { |
|||
window.location.reload(); |
|||
return; |
|||
} |
|||
|
|||
location.assign('/') |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
abp.authenticationStateValidator.init(); |
|||
|
|||
})(); |
|||
</script> |
|||
@ -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('/') |
|||
} |
|||
}); |
|||
}); |
|||
|
|||
}()); |
|||
Loading…
Reference in new issue