aggiunta gestione sessione +

cambio metodo di login
This commit is contained in:
zaccaria.majid
2022-11-16 10:16:47 +01:00
parent 160f0eaea1
commit 3bc27d3689
4 changed files with 90 additions and 46 deletions
+12 -11
View File
@@ -4,20 +4,21 @@
<div>
<div class="mb-3">
<div>
<select class="form-select" aria-label="Default select example" @bind="@idOperatore">
@if (elencoOperatori != null)
{
@foreach (var item in elencoOperatori)
{
<option value="@item.MatrOpr">@item.Cognome @item.Nome (@item.MatrOpr)</option>
}
}
</select>
</div>
<label class="form-label">Inserire auth key</label>
<input class="form-control" type="password" @bind="@authKey" />
</div>
<div>
<select class="form-select" aria-label="Default select example" @bind="@idOperatore">
@if (elencoOperatori != null)
{
@foreach (var item in elencoOperatori)
{
<option value="@item.MatrOpr">@item.Nome</option>
}
}
</select>
</div>
<div>
<button class="btn btn-primary" @onclick="login">SUBMIT</button>
</div>
+10 -5
View File
@@ -16,6 +16,7 @@ using MP.INVE.Data;
using MP.INVE.Shared;
using MP.INVE.Components;
using MP.Data.DatabaseModels;
using Blazored.SessionStorage;
namespace MP.INVE.Pages
{
@@ -25,9 +26,11 @@ namespace MP.INVE.Pages
private MiDataService MIDataservice { get; set; } = null!;
[Inject]
private NavigationManager NavManager { get; set; } = null!;
[Inject]
private ISessionStorageService sessionStorage { get; set; } = null!;
private int idOperatore { get; set; }
private string authKey { get; set; }
private int idOperatore { get; set; } = 0;
private string authKey { get; set; } = "";
private List<AnagOperatoriModel>? elencoOperatori;
@@ -35,16 +38,18 @@ namespace MP.INVE.Pages
{
//await FilterChanged.InvokeAsync(actFilter);
await Task.Delay(1);
elencoOperatori = MIDataservice.ElencoOperatori();
elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey);
}
private void login()
{
var ok = MIDataservice.LoginOperatore(idOperatore, authKey);
elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey);
if (ok)
if (elencoOperatori.Count == 1)
{
NavManager.NavigateTo("/Starter", true);
sessionStorage.SetItemAsync("MatrOpr", idOperatore);
sessionStorage.SetItemAsync("AuthKey", authKey);
}
else
{
-30
View File
@@ -9,34 +9,4 @@
@*<img src="https://qrcode.steamware.net//HOME/QR_site/JSON?val={'baseUrl':'https://iis02.egalware.com/MP/MAG/SMART/PLScanner?{0}','parameters':['MatrOpr=102']}" />*@
@code {
[Inject]
private IConfiguration Configuration { get; set; } = null!;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{101}");
await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{101}", rawCode);
}
}
protected string BaseUrlTab
{
get => $"{Configuration["ServerConf:BaseUrl"]}";
}
protected string rawCode
{
get
{
string answ = "";
answ = $"{BaseUrlTab}MatrOpr={101}&UserAuthKey={12345}";
return answ;
}
}
}
+68
View File
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using MP.INVE;
using MP.INVE.Shared;
using MP.INVE.Components;
using Blazored.SessionStorage;
namespace MP.INVE.Pages
{
public partial class Starter
{
[Inject]
private IConfiguration Configuration { get; set; } = null !;
[Inject]
private ISessionStorageService sessionStorage { get; set; } = null!;
private int idOperatore { get; set; } = 0;
private string authKey { get; set; } = "";
protected override async Task OnInitializedAsync()
{
await getId();
await getAuth();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{101}");
await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{101}", rawCode);
}
}
protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrl"]}"; }
protected async Task getId()
{
idOperatore = await sessionStorage.GetItemAsync<int>("MatrOpr");
}
protected async Task getAuth()
{
authKey = await sessionStorage.GetItemAsync<string>("AuthKey");
}
protected string rawCode
{
get
{
string answ = "";
answ = $"{BaseUrlTab}MatrOpr={idOperatore}&UserAuthKey={authKey}";
return answ;
}
}
}
}