adas
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||||
@inject ProtectedLocalStorage ProtectedLocalStore
|
@inject ProtectedLocalStorage ProtectedLocalStore
|
||||||
|
@inject UserState userState
|
||||||
|
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
@@ -108,10 +109,9 @@
|
|||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
var obtenerDatoAdmin = await ProtectedLocalStore.GetAsync<bool>("EsAdmin");
|
|
||||||
var obtenerDatoId = await ProtectedLocalStore.GetAsync<int>("idUsuario");
|
|
||||||
// Redirigir al home si no hay token y la ruta no es pública
|
// Redirigir al home si no hay token y la ruta no es pública
|
||||||
if (obtenerDatoId.Value == 0 || !obtenerDatoAdmin.Value)
|
if (userState.idUser == 0)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Navigation.NavigateTo("/", true);
|
Navigation.NavigateTo("/", true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,26 +49,31 @@
|
|||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender)
|
if (firstRender)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(urlAnterior))
|
urlAnterior = await JS.InvokeAsync<string>("eval", "document.referrer");
|
||||||
{
|
|
||||||
urlAnterior = await JS.InvokeAsync<string>("eval", "document.referer");
|
|
||||||
|
if (!string.IsNullOrEmpty(urlAnterior))
|
||||||
|
{
|
||||||
|
|
||||||
rutaActual = Navigation.ToBaseRelativePath(Navigation.Uri);
|
rutaActual = Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||||
|
|
||||||
|
|
||||||
|
if (rutaActual != "Denegado")
|
||||||
if (rutaActual != "Denegado")
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(urlAnterior) && urlAnterior.Contains("cacoa.es"))
|
|
||||||
{
|
{
|
||||||
Navigation.NavigateTo("/Denegado", true);
|
if (!urlAnterior.Contains("cacoa.es") )
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/Denegado", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
StateHasChanged();
|
else
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/Denegado", true);
|
||||||
|
}
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||||
@inject ProtectedLocalStorage ProtectedLocalStore
|
@inject ProtectedLocalStorage ProtectedLocalStore
|
||||||
|
@inject UserState userState
|
||||||
|
@inject IJSRuntime JS
|
||||||
|
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
@@ -111,15 +113,54 @@
|
|||||||
@code {
|
@code {
|
||||||
private bool MostrarExtra => Navigation.Uri.Contains("PanelControl", StringComparison.OrdinalIgnoreCase);
|
private bool MostrarExtra => Navigation.Uri.Contains("PanelControl", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
|
string? urlAnterior = "";
|
||||||
|
|
||||||
|
bool urlVaida = true;
|
||||||
|
string rutaActual = "";
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
var obtenerDatoAdmin = await ProtectedLocalStore.GetAsync<bool>("EsAdmin");
|
if (firstRender)
|
||||||
var obtenerDatoId = await ProtectedLocalStore.GetAsync<int>("idUsuario");
|
{
|
||||||
// Redirigir al home si no hay token y la ruta no es pública
|
urlAnterior = await JS.InvokeAsync<string>("eval", "document.referrer");
|
||||||
if (obtenerDatoId.Value == 0 || obtenerDatoAdmin.Value)
|
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(urlAnterior))
|
||||||
|
{
|
||||||
|
|
||||||
|
rutaActual = Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||||
|
|
||||||
|
|
||||||
|
if (rutaActual != "Denegado")
|
||||||
|
{
|
||||||
|
if (!urlAnterior.Contains("cacoa.es"))
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/Denegado", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/Denegado", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (userState.idUser == 0 )
|
||||||
{
|
{
|
||||||
Navigation.NavigateTo("/", true);
|
Navigation.NavigateTo("/", true);
|
||||||
}
|
}
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Redirigir al home si no hay token y la ruta no es pública
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,10 +70,10 @@
|
|||||||
await ProtectedLocalStore.SetAsync("EsAdmin", false);
|
await ProtectedLocalStore.SetAsync("EsAdmin", false);
|
||||||
|
|
||||||
// Limpiar almacenamiento local o sesión si se está utilizando
|
// Limpiar almacenamiento local o sesión si se está utilizando
|
||||||
// if (HttpContextAccessor?.HttpContext?.Session != null)
|
if (HttpContextAccessor?.HttpContext?.Session != null)
|
||||||
// {
|
{
|
||||||
// HttpContextAccessor.HttpContext.Session.Clear();
|
HttpContextAccessor.HttpContext.Session.Clear();
|
||||||
// }
|
}
|
||||||
|
|
||||||
var rec = await ProtectedLocalStore.GetAsync<bool>("rec");
|
var rec = await ProtectedLocalStore.GetAsync<bool>("rec");
|
||||||
if(rec.Value==true){
|
if(rec.Value==true){
|
||||||
@@ -97,6 +97,9 @@
|
|||||||
await ProtectedLocalStore.SetAsync("idUsuario", -1);
|
await ProtectedLocalStore.SetAsync("idUsuario", -1);
|
||||||
await ProtectedLocalStore.SetAsync("EsAdmin", true);
|
await ProtectedLocalStore.SetAsync("EsAdmin", true);
|
||||||
|
|
||||||
|
UserState.idUser = -1;
|
||||||
|
UserState.PuedeAcceder =true;
|
||||||
|
|
||||||
Navigation.NavigateTo("/PanelControlConf", forceLoad: true);
|
Navigation.NavigateTo("/PanelControlConf", forceLoad: true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -113,6 +116,9 @@
|
|||||||
await ProtectedLocalStore.SetAsync("idUsuario", usuario.idUsuario);
|
await ProtectedLocalStore.SetAsync("idUsuario", usuario.idUsuario);
|
||||||
await ProtectedLocalStore.SetAsync("EsAdmin", false);
|
await ProtectedLocalStore.SetAsync("EsAdmin", false);
|
||||||
|
|
||||||
|
UserState.idUser = usuario.idUsuario;
|
||||||
|
UserState.PuedeAcceder =true;
|
||||||
|
|
||||||
|
|
||||||
if (recuerda)
|
if (recuerda)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
private readonly object _lock = new object();
|
private readonly object _lock = new object();
|
||||||
private int _idUser;
|
private int _idUser;
|
||||||
private bool _esAdmin;
|
private bool _esAdmin;
|
||||||
|
private bool _puedeAcceder;
|
||||||
public int idUser
|
public int idUser
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -41,5 +42,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool PuedeAcceder
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
return _puedeAcceder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
_puedeAcceder = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user