Aggiunta gestione preliminare AUTH
This commit is contained in:
+14
-12
@@ -1,12 +1,14 @@
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(MainLayout)">
|
||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
<CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(MainLayout)">
|
||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
</CascadingAuthenticationState>
|
||||
@@ -0,0 +1,17 @@
|
||||
@using System.Security.Claims
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
<div class="d-flex w-100 justify-content-between">
|
||||
<div class="px-2">
|
||||
<AuthorizeView>
|
||||
<i class="fas fa-user-alt"></i> <b>@userName</b>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
<div class="pe-2">
|
||||
<button class="btn btn-primary" @onclick="() => flushCache()" title="Forza Refresh Dati correnti"> Force Reload </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.JSInterop;
|
||||
using StockMan.CORE.Data;
|
||||
|
||||
namespace StockMan.CORE.Components
|
||||
{
|
||||
public partial class CmpTop
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public async Task flushCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await SDService.FlushRedisCache();
|
||||
await Task.Delay(1);
|
||||
// rimando a pagina corrente
|
||||
NavManager.NavigateTo(NavManager.Uri, true);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JSRuntime { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected StockDataService SDService { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await forceReload();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private string userName = "";
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
[Inject]
|
||||
private NavigationManager NavManager { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task forceReload()
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
if (user.Identity != null && user.Identity.IsAuthenticated)
|
||||
{
|
||||
userName = $"{user.Identity.Name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = "N.A.";
|
||||
}
|
||||
}
|
||||
|
||||
private async void MService_EA_ShowSearch()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await InvokeAsync(() => StateHasChanged());
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,10 @@
|
||||
</div>
|
||||
<div>
|
||||
<div class="bot">
|
||||
@if (!isComp)
|
||||
<AuthorizeView>
|
||||
<i class="fas fa-user-alt"></i> <b>@userName</b>
|
||||
</AuthorizeView>
|
||||
@* @if (!isComp)
|
||||
{
|
||||
@if (User.Contains("/"))
|
||||
{
|
||||
@@ -123,7 +126,7 @@
|
||||
@($"{User.Substring(0, 1).ToUpper()}")
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}*@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,53 +1,61 @@
|
||||
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 StockMan.CORE;
|
||||
using StockMan.CORE.Shared;
|
||||
using StockMan.CORE.Data;
|
||||
using StockMan.Data.DbModels;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace StockMan.CORE.Components
|
||||
{
|
||||
public partial class NewNavMenu
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Parameter]
|
||||
public List<PermessiModel>? NavMenuLinks { get; set; } = null;
|
||||
|
||||
public List<PermessiModel> NavMenuLinksChild { get; set; } = new List<PermessiModel>();
|
||||
|
||||
[Parameter]
|
||||
public string Theme { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string Title { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string User { get; set; } = "";
|
||||
#endregion Public Properties
|
||||
|
||||
[Parameter]
|
||||
public string Theme { get; set; } = "";
|
||||
#region Protected Fields
|
||||
|
||||
protected bool isChildOpen = false;
|
||||
protected bool isComp = false;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
[Inject]
|
||||
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = null!;
|
||||
|
||||
protected int currChildOpen { get; set; } = 0;
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JSRuntime { get; set; } = null!;
|
||||
|
||||
protected bool isComp = false;
|
||||
protected bool isChildOpen = false;
|
||||
public List<PermessiModel> NavMenuLinksChild { get; set; } = new List<PermessiModel>();
|
||||
#endregion Protected Properties
|
||||
|
||||
protected int currChildOpen { get; set; } = 0;
|
||||
#region Protected Methods
|
||||
|
||||
protected void compress()
|
||||
{
|
||||
JSRuntime.InvokeVoidAsync("closeNav");
|
||||
isComp = true;
|
||||
}
|
||||
|
||||
protected void deCompress()
|
||||
{
|
||||
JSRuntime.InvokeVoidAsync("openNav");
|
||||
JSRuntime.InvokeVoidAsync("showMenuBtn");
|
||||
isComp = false;
|
||||
}
|
||||
|
||||
protected void doShowChildren(int id)
|
||||
{
|
||||
if (currChildOpen != 0)
|
||||
@@ -82,26 +90,10 @@ namespace StockMan.CORE.Components
|
||||
else
|
||||
{
|
||||
JSRuntime.InvokeVoidAsync("doHideChildren", id);
|
||||
currChildOpen= 0;
|
||||
currChildOpen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected string isActive(int gruppo)
|
||||
{
|
||||
string answ = "navLinkItem";
|
||||
if (gruppo == currChildOpen)
|
||||
{
|
||||
answ = "navLinkItemActive";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected void deCompress()
|
||||
{
|
||||
JSRuntime.InvokeVoidAsync("openNav");
|
||||
JSRuntime.InvokeVoidAsync("showMenuBtn");
|
||||
isComp = false;
|
||||
}
|
||||
protected bool hasChild(int group)
|
||||
{
|
||||
bool hasIt = false;
|
||||
@@ -115,5 +107,47 @@ namespace StockMan.CORE.Components
|
||||
}
|
||||
return hasIt;
|
||||
}
|
||||
|
||||
protected string isActive(int gruppo)
|
||||
{
|
||||
string answ = "navLinkItem";
|
||||
if (gruppo == currChildOpen)
|
||||
{
|
||||
answ = "navLinkItemActive";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await forceReload();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private string userName = "";
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task forceReload()
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
if (user.Identity != null && user.Identity.IsAuthenticated)
|
||||
{
|
||||
userName = $"{user.Identity.Name}";
|
||||
// cercare in tabella operators e salvare sigla da registrare nei vari records sul DB
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = "N.A.";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,18 @@ using StockMan.Data;
|
||||
using System.Globalization;
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
using Microsoft.AspNetCore.Authentication.Negotiate;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
//builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
||||
// .AddNegotiate();
|
||||
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
||||
.AddNegotiate();
|
||||
|
||||
//builder.Services.AddAuthorization(options =>
|
||||
//{
|
||||
// // By default, all incoming requests will be authorized according to the default policy.
|
||||
// options.FallbackPolicy = options.DefaultPolicy;
|
||||
//});
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
// By default, all incoming requests will be authorized according to the default policy.
|
||||
options.FallbackPolicy = options.DefaultPolicy;
|
||||
});
|
||||
|
||||
// configuration setup
|
||||
ConfigurationManager configuration = builder.Configuration;
|
||||
@@ -80,8 +81,8 @@ app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
//app.UseAuthentication();
|
||||
//app.UseAuthorization();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapBlazorHub();
|
||||
app.MapFallbackToPage("/_Host");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"windowsAuthentication": true,
|
||||
"anonymousAuthentication": false,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:15225",
|
||||
"sslPort": 44328
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<div class="page">
|
||||
<div class="nav" id="navMain">
|
||||
<NewNavMenu NavMenuLinks="@navMenuLinks" Title="STOCK MAN" User="steamw/zaccaria.majid"></NewNavMenu>
|
||||
<NewNavMenu NavMenuLinks="@navMenuLinks" Title="STOCK MAN"></NewNavMenu>
|
||||
</div>
|
||||
|
||||
<main>
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EgwCoreLib.Razor" Version="1.3.2302.507" />
|
||||
<PackageReference Include="EgwCoreLib.Razor" Version="1.4.2302.1709" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.13" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.6.90" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user