128 lines
4.9 KiB
Plaintext
128 lines
4.9 KiB
Plaintext
@page "/"
|
|
@using HerramientaCASA.Model
|
|
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
|
@inject ProtectedLocalStorage ProtectedLocalStore
|
|
@rendermode InteractiveServer
|
|
@layout LoginLayout
|
|
@inject IHttpContextAccessor HttpContextAccessor
|
|
@inject NavigationManager Navigation
|
|
@inject UserState UserState
|
|
|
|
|
|
<div class="fondo">
|
|
<div class="back">
|
|
<div class="div-center">
|
|
<div class="content">
|
|
<img src="Content/Imagenes/CACOA-6.png" height="49" />
|
|
<h4 class="mt-2">Acceso a la Herramienta</h4>
|
|
<hr />
|
|
<EditForm Model="login" FormName="loginForm" OnValidSubmit="Acceder" >
|
|
<DataAnnotationsValidator></DataAnnotationsValidator>
|
|
|
|
<div class="form-group">
|
|
<label for="exampleInputEmail1">Clave de acceso</label>
|
|
<input type="number" class="form-control" @bind-value="@login.codigo" placeholder="0000000000000" id="clave" />
|
|
<ValidationMessage For="() => login.codigo" />
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Password</label>
|
|
<div class="input-group">
|
|
<PasswordInput Class="form-control" @bind-Value="@login.password" Id="pass"/>
|
|
</div>
|
|
<ValidationMessage For="() => login.password" />
|
|
</div>
|
|
<div class="form-check" style="gap:10px;">
|
|
@* <input type="checkbox" class="form-check-input" id="chkRecuerda" /> *@
|
|
<CheckboxInput Class="form-check-input" Id="chkRecuerda" Value=@recuerda ValueExpression="() => recuerda" ValueChanged="(value) => checkCambiado(value)" />
|
|
<label class="form-check-label" for="Recuerdame">Recordarme</label>
|
|
</div>
|
|
<div class="form-group">
|
|
<small class="form-text text-muted">Si es la primera vez que utiliza la herramienta, <a href="NuevoAcceso" class="mt-2">cree una nueva clave de acceso</a></small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<p class="form-text text-muted" style="color:red !important">@mensajeError</p>
|
|
</div>
|
|
<button type="submit" class="btnBlue"> Acceder </button>
|
|
</EditForm>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@code {
|
|
|
|
public tsHerramientasCACOA bd;
|
|
private LoginVM login = new LoginVM();
|
|
private string mensajeError = "";
|
|
private bool recuerda = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
|
|
|
|
await ProtectedLocalStore.SetAsync("idUsuario", 0);
|
|
await ProtectedLocalStore.SetAsync("EsAdmin", false);
|
|
|
|
// Limpiar almacenamiento local o sesión si se está utilizando
|
|
// if (HttpContextAccessor?.HttpContext?.Session != null)
|
|
// {
|
|
// HttpContextAccessor.HttpContext.Session.Clear();
|
|
// }
|
|
|
|
var rec = await ProtectedLocalStore.GetAsync<bool>("rec");
|
|
if(rec.Value==true){
|
|
var usuario = await ProtectedLocalStore.GetAsync<int>("US");
|
|
var clave = await ProtectedLocalStore.GetAsync<string>("PS");
|
|
login.codigo = usuario.Value;
|
|
login.password = clave.Value;
|
|
recuerda = true;
|
|
}
|
|
|
|
}
|
|
private async void checkCambiado(bool e)
|
|
{
|
|
recuerda = e;
|
|
}
|
|
private async Task Acceder()
|
|
{
|
|
if (login.codigo == -534610 && login.password == "sRg1406.")
|
|
// if (login.codigo == -1 && login.password == "-1")
|
|
{
|
|
await ProtectedLocalStore.SetAsync("idUsuario", -1);
|
|
await ProtectedLocalStore.SetAsync("EsAdmin", true);
|
|
|
|
Navigation.NavigateTo("/PanelControlConf", forceLoad: true);
|
|
}
|
|
else
|
|
{
|
|
var usuario = bd.usuarios.FirstOrDefault(x => x.Codigo == login.codigo && x.Contrasena == login.password);
|
|
|
|
if (usuario == null)
|
|
{
|
|
mensajeError = "Usuario no encontrado en la base de datos.";
|
|
}
|
|
else
|
|
{
|
|
|
|
await ProtectedLocalStore.SetAsync("idUsuario", usuario.idUsuario);
|
|
await ProtectedLocalStore.SetAsync("EsAdmin", false);
|
|
|
|
|
|
if (recuerda)
|
|
{
|
|
await ProtectedLocalStore.SetAsync("US", login.codigo);
|
|
await ProtectedLocalStore.SetAsync("PS", login.password);
|
|
await ProtectedLocalStore.SetAsync("rec", true);
|
|
}
|
|
else
|
|
{
|
|
await ProtectedLocalStore.SetAsync("rec", false);
|
|
}
|
|
|
|
|
|
Navigation.NavigateTo("/PanelControl", forceLoad: true);
|
|
}
|
|
}
|
|
}
|
|
}
|