This commit is contained in:
2025-07-28 13:24:07 +02:00
12 changed files with 37 additions and 30 deletions

View File

@@ -4,7 +4,8 @@
@using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web
@inject NavigationManager Navigation @inject NavigationManager Navigation
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
<head> <head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
@@ -97,8 +98,8 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var obtenerDatoAdmin = await ProtectedSessionStore.GetAsync<bool>("EsAdmin"); var obtenerDatoAdmin = await ProtectedLocalStore.GetAsync<bool>("EsAdmin");
var obtenerDatoId = await ProtectedSessionStore.GetAsync<int>("idUsuario"); 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 (obtenerDatoId.Value == 0 || !obtenerDatoAdmin.Value)
{ {

View File

@@ -4,7 +4,8 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
@inject NavigationManager Navigation @inject NavigationManager Navigation
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
<head> <head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
@@ -102,8 +103,8 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var obtenerDatoAdmin = await ProtectedSessionStore.GetAsync<bool>("EsAdmin"); var obtenerDatoAdmin = await ProtectedLocalStore.GetAsync<bool>("EsAdmin");
var obtenerDatoId = await ProtectedSessionStore.GetAsync<int>("idUsuario"); 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 (obtenerDatoId.Value == 0 || obtenerDatoAdmin.Value)
{ {

View File

@@ -5,7 +5,8 @@
@using bdHerramientaCACOA.HerramientaURBAN @using bdHerramientaCACOA.HerramientaURBAN
@using bdHerramientaCACOA.db @using bdHerramientaCACOA.db
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject UserState UserState @inject UserState UserState
@@ -80,7 +81,7 @@
private async void cargarListaSimulaciones() private async void cargarListaSimulaciones()
{ {
var idUser = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var idUser = await ProtectedLocalStore.GetAsync<int>("idUsuario");
listadoSimulaciones = bd.simulaciones.Include(x => x.idTipoSimulacionNavigation).Where(x => x.idCodigo == idUser.Value && (x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA.CASA" || x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA.URBAND") && x.idSimulacion != datosDespachoClonado.idSimulacion).ToList(); listadoSimulaciones = bd.simulaciones.Include(x => x.idTipoSimulacionNavigation).Where(x => x.idCodigo == idUser.Value && (x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA.CASA" || x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA.URBAND") && x.idSimulacion != datosDespachoClonado.idSimulacion).ToList();

View File

@@ -6,7 +6,8 @@
@using bdHerramientaCACOA.db @using bdHerramientaCACOA.db
@using Newtonsoft.Json @using Newtonsoft.Json
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@rendermode InteractiveServer @rendermode InteractiveServer
@inject NavigationManager Navigation @inject NavigationManager Navigation
@@ -166,7 +167,7 @@
nombreOriginal = casa.NombreSimulacion; nombreOriginal = casa.NombreSimulacion;
} }
var obtenerID = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var obtenerID = await ProtectedLocalStore.GetAsync<int>("idUsuario");
idUser = obtenerID.Value; idUser = obtenerID.Value;
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -7,7 +7,8 @@
@using bdHerramientaCACOA.HerramientaURBAN @using bdHerramientaCACOA.HerramientaURBAN
@using bdHerramientaCACOA.db @using bdHerramientaCACOA.db
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@rendermode InteractiveServer @rendermode InteractiveServer
@inject NavigationManager Navigation @inject NavigationManager Navigation
@@ -145,7 +146,7 @@
} }
var obtenerID = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var obtenerID = await ProtectedLocalStore.GetAsync<int>("idUsuario");
idUser = obtenerID.Value; idUser = obtenerID.Value;
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -5,7 +5,8 @@
@using bdHerramientaCACOA.db @using bdHerramientaCACOA.db
@using HerramientaCASA.Components.Pages.LicitacionesGrids @using HerramientaCASA.Components.Pages.LicitacionesGrids
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@page "/LicitacionCASA" @page "/LicitacionCASA"
@page "/LicitacionCASA/{idSimulador}" @page "/LicitacionCASA/{idSimulador}"
@@ -264,7 +265,7 @@
nombreOriginal = objetoLicitaciones.Descripcion; nombreOriginal = objetoLicitaciones.Descripcion;
} }
var obtenerID = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var obtenerID = await ProtectedLocalStore.GetAsync<int>("idUsuario");
idUser = obtenerID.Value; idUser = obtenerID.Value;
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -8,7 +8,8 @@
@using bdHerramientaCACOA.HerramientaURBAN @using bdHerramientaCACOA.HerramientaURBAN
@using bdHerramientaCACOA.db @using bdHerramientaCACOA.db
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@inject NavigationManager Navigation @inject NavigationManager Navigation
<Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="mensajes" Placement="ToastsPlacement.BottomCenter" /> <Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="mensajes" Placement="ToastsPlacement.BottomCenter" />
@@ -272,7 +273,7 @@
} }
var obtenerID = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var obtenerID = await ProtectedLocalStore.GetAsync<int>("idUsuario");
idUser = obtenerID.Value; idUser = obtenerID.Value;
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -6,7 +6,7 @@
@rendermode InteractiveServer @rendermode InteractiveServer
@layout LoginLayout @layout LoginLayout
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
<div class="back"> <div class="back">
@@ -32,7 +32,7 @@
{ {
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
var obtenerId = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var obtenerId = await ProtectedLocalStore.GetAsync<int>("idUsuario");
claveUsuario = obtenerId.Value; claveUsuario = obtenerId.Value;
if (claveUsuario == 0 || claveUsuario == null) if (claveUsuario == 0 || claveUsuario == null)

View File

@@ -1,7 +1,7 @@
@page "/" @page "/"
@using HerramientaCASA.Model @using HerramientaCASA.Model
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@rendermode InteractiveServer @rendermode InteractiveServer
@layout LoginLayout @layout LoginLayout
@inject IHttpContextAccessor HttpContextAccessor @inject IHttpContextAccessor HttpContextAccessor
@@ -59,8 +59,8 @@
{ {
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
await ProtectedSessionStore.SetAsync("idUsuario", 0); await ProtectedLocalStore.SetAsync("idUsuario", 0);
await ProtectedSessionStore.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)
@@ -74,8 +74,8 @@
//if (login.codigo == -534610 && login.password == "sRg1406.") //if (login.codigo == -534610 && login.password == "sRg1406.")
if (login.codigo == -1 && login.password == "-1") if (login.codigo == -1 && login.password == "-1")
{ {
await ProtectedSessionStore.SetAsync("idUsuario", -1); await ProtectedLocalStore.SetAsync("idUsuario", -1);
await ProtectedSessionStore.SetAsync("EsAdmin", true); await ProtectedLocalStore.SetAsync("EsAdmin", true);
Navigation.NavigateTo("/PanelControlConf", forceLoad: true); Navigation.NavigateTo("/PanelControlConf", forceLoad: true);
} }
@@ -90,8 +90,8 @@
else else
{ {
await ProtectedSessionStore.SetAsync("idUsuario", usuario.idUsuario); await ProtectedLocalStore.SetAsync("idUsuario", usuario.idUsuario);
await ProtectedSessionStore.SetAsync("EsAdmin", false); await ProtectedLocalStore.SetAsync("EsAdmin", false);
Navigation.NavigateTo("/PanelControl", forceLoad: true); Navigation.NavigateTo("/PanelControl", forceLoad: true);

View File

@@ -6,7 +6,7 @@
@rendermode InteractiveServer @rendermode InteractiveServer
@layout LoginLayout @layout LoginLayout
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
<div class="back"> <div class="back">
@@ -61,7 +61,7 @@
nuevoAcceso.Codigo = nuevoAcceso.idUsuario; nuevoAcceso.Codigo = nuevoAcceso.idUsuario;
bd.SaveChanges(); bd.SaveChanges();
await ProtectedSessionStore.SetAsync("idUsuario", nuevoAcceso.idUsuario); await ProtectedLocalStore.SetAsync("idUsuario", nuevoAcceso.idUsuario);
Navigation.NavigateTo("/ClaveGenerada", forceLoad: true); Navigation.NavigateTo("/ClaveGenerada", forceLoad: true);

View File

@@ -2,7 +2,7 @@
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using bdHerramientaCACOA.db @using bdHerramientaCACOA.db
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore @inject ProtectedLocalStorage ProtectedLocalStore
@inject UserState UserState @inject UserState UserState
@@ -71,7 +71,7 @@
{ {
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: true); bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: true);
var obtenerID = await ProtectedSessionStore.GetAsync<int>("idUsuario"); var obtenerID = await ProtectedLocalStore.GetAsync<int>("idUsuario");
idUser = obtenerID.Value; idUser = obtenerID.Value;
listadoSimulaciones = bd.simulaciones.Include(x => x.idTipoSimulacionNavigation).Include(x => x.idFicheroJSONNavigation).Where(x => x.idCodigo == idUser && x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA." + TipoSimulacion).ToList(); listadoSimulaciones = bd.simulaciones.Include(x => x.idTipoSimulacionNavigation).Include(x => x.idFicheroJSONNavigation).Where(x => x.idCodigo == idUser && x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA." + TipoSimulacion).ToList();

View File

@@ -39,7 +39,7 @@ builder.Services.AddSession(options =>
builder.Services.AddBlazorBootstrap(); builder.Services.AddBlazorBootstrap();
builder.Services.AddAntiforgery(); builder.Services.AddAntiforgery();
builder.Services.AddSingleton<UserState>(); builder.Services.AddSingleton<UserState>();
builder.Services.AddScoped<ProtectedSessionStorage>(); builder.Services.AddScoped<ProtectedLocalStorage>();
var app = builder.Build(); var app = builder.Build();