rimosso file inutili
This commit is contained in:
@ -1,59 +0,0 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace StandManager.Components.Account
|
||||
{
|
||||
internal sealed class IdentityRedirectManager(NavigationManager navigationManager)
|
||||
{
|
||||
public const string StatusCookieName = "Identity.StatusMessage";
|
||||
|
||||
private static readonly CookieBuilder StatusCookieBuilder = new()
|
||||
{
|
||||
SameSite = SameSiteMode.Strict,
|
||||
HttpOnly = true,
|
||||
IsEssential = true,
|
||||
MaxAge = TimeSpan.FromSeconds(5),
|
||||
};
|
||||
|
||||
[DoesNotReturn]
|
||||
public void RedirectTo(string? uri)
|
||||
{
|
||||
uri ??= "";
|
||||
|
||||
// Prevent open redirects.
|
||||
if (!Uri.IsWellFormedUriString(uri, UriKind.Relative))
|
||||
{
|
||||
uri = navigationManager.ToBaseRelativePath(uri);
|
||||
}
|
||||
|
||||
// During static rendering, NavigateTo throws a NavigationException which is handled by the framework as a redirect.
|
||||
// So as long as this is called from a statically rendered Identity component, the InvalidOperationException is never thrown.
|
||||
navigationManager.NavigateTo(uri);
|
||||
throw new InvalidOperationException($"{nameof(IdentityRedirectManager)} can only be used during static rendering.");
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
public void RedirectTo(string uri, Dictionary<string, object?> queryParameters)
|
||||
{
|
||||
var uriWithoutQuery = navigationManager.ToAbsoluteUri(uri).GetLeftPart(UriPartial.Path);
|
||||
var newUri = navigationManager.GetUriWithQueryParameters(uriWithoutQuery, queryParameters);
|
||||
RedirectTo(newUri);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
public void RedirectToWithStatus(string uri, string message, HttpContext context)
|
||||
{
|
||||
context.Response.Cookies.Append(StatusCookieName, message, StatusCookieBuilder.Build(context));
|
||||
RedirectTo(uri);
|
||||
}
|
||||
|
||||
private string CurrentPath => navigationManager.ToAbsoluteUri(navigationManager.Uri).GetLeftPart(UriPartial.Path);
|
||||
|
||||
[DoesNotReturn]
|
||||
public void RedirectToCurrentPage() => RedirectTo(CurrentPath);
|
||||
|
||||
[DoesNotReturn]
|
||||
public void RedirectToCurrentPageWithStatus(string message, HttpContext context)
|
||||
=> RedirectToWithStatus(CurrentPath, message, context);
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StandManager.Domain.Entita;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace StandManager.Components.Account
|
||||
{
|
||||
internal sealed class IdentityRevalidatingAuthenticationStateProvider(
|
||||
ILoggerFactory loggerFactory,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
IOptions<IdentityOptions> options)
|
||||
: RevalidatingServerAuthenticationStateProvider(loggerFactory)
|
||||
{
|
||||
protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30);
|
||||
|
||||
protected override async Task<bool> ValidateAuthenticationStateAsync(
|
||||
AuthenticationState authenticationState, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the user manager from a new scope to ensure it fetches fresh data
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
return await ValidateSecurityStampAsync(userManager, authenticationState.User);
|
||||
}
|
||||
|
||||
private async Task<bool> ValidateSecurityStampAsync(UserManager<ApplicationUser> userManager, ClaimsPrincipal principal)
|
||||
{
|
||||
var user = await userManager.GetUserAsync(principal);
|
||||
if (user is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!userManager.SupportsUserSecurityStamp)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var principalStamp = principal.FindFirstValue(options.Value.ClaimsIdentity.SecurityStampClaimType);
|
||||
var userStamp = await userManager.GetSecurityStampAsync(user);
|
||||
return principalStamp == userStamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using StandManager.Domain.Entita;
|
||||
|
||||
namespace StandManager.Components.Account
|
||||
{
|
||||
internal sealed class IdentityUserAccessor(UserManager<ApplicationUser> userManager, IdentityRedirectManager redirectManager)
|
||||
{
|
||||
public async Task<ApplicationUser> GetRequiredUserAsync(HttpContext context)
|
||||
{
|
||||
var user = await userManager.GetUserAsync(context.User);
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
redirectManager.RedirectToWithStatus("Account/InvalidUser", $"Error: Unable to load user with ID '{userManager.GetUserId(context.User)}'.", context);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-md-3">
|
||||
<a href="/management">
|
||||
<a href="/">
|
||||
<img src="/Logo_dac.png" width="80" class="">
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
@page "/auth"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>Auth</PageTitle>
|
||||
|
||||
<h1>You are authenticated</h1>
|
||||
|
||||
<AuthorizeView>
|
||||
Hello @context.User.Identity?.Name!
|
||||
</AuthorizeView>
|
||||
@ -1,89 +0,0 @@
|
||||
@rendermode InteractiveServer
|
||||
@layout PublicLayout
|
||||
@page "/management/login"
|
||||
@using System.Security.Claims
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using OAService.Domain.Entita
|
||||
@using StandManager.Components.Layout
|
||||
@using StandManager.Domain.Entita
|
||||
@using StandManager.Model
|
||||
@using StandManager.Service.Interfaces
|
||||
@using Microsoft.AspNetCore.Http
|
||||
@inject NavigationManager Navigation
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@inject HttpClient Http
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject IUserStore<ApplicationUser> UserStore
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
|
||||
<div class="page page-center">
|
||||
<div class="container container-tight py-4">
|
||||
<div class="text-center mb-4">
|
||||
</div>
|
||||
<div class="card card-md">
|
||||
<div class="card-body">
|
||||
<h2 class="h2 text-center mb-4">Accedi</h2>
|
||||
<EditForm Model="model" OnValidSubmit="HandleValidSubmit" FormName="loginForm">
|
||||
<DataAnnotationsValidator/>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Email</label>
|
||||
<InputText class="form-control" @bind-Value="model!.Email"/>
|
||||
<ValidationMessage For="@(() => model!.Email)"/>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Password</label>
|
||||
<InputText class="form-control" @bind-Value="model!.Password" type="password"/>
|
||||
<ValidationMessage For="@(() => model!.Password)"/>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100">
|
||||
Accedi
|
||||
</button>
|
||||
|
||||
@if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger mt-3">@errorMessage</div>
|
||||
}
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromForm]
|
||||
private LoginModel? model { get; set; }
|
||||
|
||||
private string? errorMessage;
|
||||
protected override void OnInitialized() => model ??= new();
|
||||
private async Task HandleValidSubmit()
|
||||
{
|
||||
var u = UserManager.Users.FirstOrDefault();
|
||||
var result = await SignInManager.CheckPasswordSignInAsync(u, "test123pwd@", lockoutOnFailure: false);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
await SignInManager.SignInAsync(u, isPersistent: true, "standmanager");
|
||||
}
|
||||
Navigation.NavigateTo("management/Dashboard");
|
||||
// var response = await Http.PostAsJsonAsync("/management/adminLogin", model);
|
||||
|
||||
// if (!response.IsSuccessStatusCode)
|
||||
// {
|
||||
// // leggiamo il messaggio dall'endpoint (opzionale)
|
||||
// var msg = await response.Content.ReadAsStringAsync();
|
||||
// errorMessage = string.IsNullOrWhiteSpace(msg)
|
||||
// ? "Credenziali non valide."
|
||||
// : msg;
|
||||
|
||||
// return;
|
||||
// }
|
||||
// var u = await _managerService.UtenteService.RicercaPer(x => x.Email == model!.Email);
|
||||
// await SignInManager.SignInAsync(new ApplicationUser(), new AuthenticationProperties { IsPersistent = false });
|
||||
// // Login ok → vai al management
|
||||
// Navigation.NavigateTo("management/Dashboard");
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<h1>Questo è il layout pubblico</h1>
|
||||
|
||||
<button @onclick="SayHi">Salutami</button>
|
||||
<p>@message</p>
|
||||
|
||||
@code {
|
||||
private string message = "In attesa di saluto…";
|
||||
|
||||
private void SayHi()
|
||||
{
|
||||
message = $"Ciao dal layout pubblico alle {DateTime.Now:T}";
|
||||
Console.WriteLine("Ciao dal layout pubblico"); // log server
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,14 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Radzen;
|
||||
using StandManager.Components;
|
||||
using StandManager.Components.Account;
|
||||
using StandManager.Domain.Entita;
|
||||
using StandManager.Infrastructure.DAL.Context;
|
||||
using StandManager.Model;
|
||||
using StandManager.Service;
|
||||
using StandManager.Service.Interfaces;
|
||||
using StandManager.Service.Repository;
|
||||
using StandManager.Utils;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -23,9 +17,6 @@ builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
//builder.Services.AddScoped<IdentityUserAccessor>();
|
||||
//builder.Services.AddScoped<IdentityRedirectManager>();
|
||||
//builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();
|
||||
|
||||
builder.Services.Configure<IdentityOptions>(options =>
|
||||
{
|
||||
@ -65,6 +56,7 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc
|
||||
options.Cookie.Name = "auth_token";
|
||||
options.Cookie.MaxAge = TimeSpan.FromMinutes(30);
|
||||
options.LoginPath = "/account/login";
|
||||
options.LogoutPath = "/account/logout";
|
||||
options.AccessDeniedPath = "/access-denied";
|
||||
});
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
@ -27,47 +27,6 @@
|
||||
<ProjectReference Include="..\StandManager.Service\StandManager.Service.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\AccessDenied.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ConfirmEmail.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ConfirmEmailChange.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ExternalLogin.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ForgotPassword.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ForgotPasswordConfirmation.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\InvalidPasswordReset.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\InvalidUser.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Lockout.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Login.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\LoginWith2fa.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\LoginWithRecoveryCode.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\ChangePassword.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\DeletePersonalData.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\Disable2fa.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\Email.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\EnableAuthenticator.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\ExternalLogins.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\GenerateRecoveryCodes.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\Index.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\PersonalData.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\ResetAuthenticator.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\SetPassword.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\TwoFactorAuthentication.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Manage\_Imports.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\Register.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\RegisterConfirmation.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ResendEmailConfirmation.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ResetPassword.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\ResetPasswordConfirmation.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Pages\_Imports.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\AccountLayout.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\ExternalLoginPicker.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\ManageLayout.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\ManageNavMenu.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\RedirectToLogin.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\ShowRecoveryCodes.razor" />
|
||||
<_ContentIncludedByDefault Remove="Components\Account\Shared\StatusMessage.razor" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="OAService.Domain">
|
||||
<HintPath>..\Libs\OAService.Domain.dll</HintPath>
|
||||
|
||||
Reference in New Issue
Block a user