Aggiunta login

This commit is contained in:
2025-05-09 14:43:46 +02:00
parent ea52494dfb
commit eb1dc8daa2
22 changed files with 440 additions and 534 deletions

View File

@@ -39,7 +39,7 @@
protected override Task OnInitializedAsync()
{
NavigationManager.LocationChanged += (sender, args) =>
NavigationManager.LocationChanged += (_, args) =>
{
var location = args.Location.Remove(0, NavigationManager.BaseUri.Length);

View File

@@ -0,0 +1,8 @@
<div class="spinner-container @(FullScreen ? "" : "not-fullScreen")">
<span class="loader"></span>
</div>
@code
{
[Parameter] public bool FullScreen { get; set; } = true;
}

View File

@@ -0,0 +1,43 @@
.spinner-container {
display: flex;
justify-content: center;
height: calc(100vh - 10.1rem);
align-items: center;
color: var(--mud-palette-primary);
}
.not-fullScreen {
height: auto !important;
padding: 2rem 0 !important;
}
.loader {
width: 50px;
aspect-ratio: 1;
border-radius: 50%;
border: 8px solid #0000;
border-right-color: var(--mud-palette-secondary);
position: relative;
animation: l24 1s infinite linear;
}
.loader:before,
.loader:after {
content: "";
position: absolute;
inset: -8px;
border-radius: 50%;
border: inherit;
animation: inherit;
animation-duration: 2s;
}
.loader:after {
animation-duration: 4s;
}
@keyframes l24 {
100% {
transform: rotate(1turn)
}
}

View File

@@ -1,4 +1,5 @@
@page "/Calendar"
@attribute [Authorize]
@using Template.Shared.Components.Layout
<HeaderLayout Title="Agenda" />

View File

@@ -1,4 +1,5 @@
@page "/"
@attribute [Authorize]
@code
{

View File

@@ -0,0 +1,101 @@
@page "/login"
@using Template.Shared.Components.Layout.Spinner
@using Template.Shared.Core.Services
@inject IUserAccountService UserAccountService
@inject AppAuthenticationStateProvider AuthenticationStateProvider
@if (Spinner)
{
<SpinnerLayout/>
}
else
{
<div class="center-box container d-flex justify-content-center align-items-center min-vh-100">
<div class="row border rounded-4 bg-white shadow box-area">
<div class="appName rounded-4 d-flex justify-content-center align-items-center flex-column">
<span>Nome App</span>
</div>
<div class="col-md-6 right-box">
<div class="row align-items-center">
<div class="input-group mb-2">
<MudTextField @bind-Value="UserData.Username" Label="Username" Variant="Variant.Text"/>
</div>
<div class="input-group mb-2">
<MudTextField @bind-Value="UserData.Password" Label="Password" Variant="Variant.Text"/>
</div>
<div class="input-group mb-4">
<MudTextField @bind-Value="UserData.CodHash" Label="Profilo azienda" Variant="Variant.Text"/>
</div>
<div class="input-group">
<div class="button-login" @onclick="SignInUser">
<span>Login</span>
</div>
</div>
</div>
<div class="my-4 login-footer">
<span>Powered by</span>
<img src="_content/Template.Shared/images/logoIntegry.svg" class="img-fluid" alt="Integry">
</div>
@if (_attemptFailed)
{
<MudAlert Class="my-3" Dense="true" Severity="Severity.Error" Variant="Variant.Filled">@ErrorMessage</MudAlert>
}
</div>
</div>
</div>
}
@code {
private SignIn UserData { get; } = new();
private bool Spinner { get; set; }
private string ErrorMessage { get; set; } = "";
private bool _attemptFailed;
protected override void OnInitialized()
{
UserData.CodHash = LocalStorage.GetString("codHash");
StateHasChanged();
}
private async Task SignInUser()
{
_attemptFailed = false;
if (!string.IsNullOrEmpty(UserData.Username) && !string.IsNullOrEmpty(UserData.Password) && !string.IsNullOrEmpty(UserData.CodHash))
{
Spinner = true;
StateHasChanged();
try
{
await UserAccountService.Login(UserData.Username, UserData.Password, UserData.CodHash);
AuthenticationStateProvider.NotifyAuthenticationState(); //Chiamato per forzare il refresh
LocalStorage.SetString("codHash", UserData.CodHash);
NavigationManager.NavigateTo("/");
StateHasChanged();
}
catch (Exception e)
{
Spinner = false;
StateHasChanged();
ErrorMessage = e.Message;
_attemptFailed = true;
Console.WriteLine(e);
// Logger<>.LogError(e, e.Message);
}
}
}
public class SignIn
{
public string? Username { get; set; }
public string? Password { get; set; }
public string? CodHash { get; set; }
}
}

View File

@@ -0,0 +1,61 @@
.center-box {
margin-top: -1.1rem !important; /* remove page padding */
}
.box-area {
width: 930px;
}
.right-box {
padding: 15px 30px 0 30px;
}
::placeholder {
font-size: 16px;
}
.rounded-4 {
border-radius: 20px;
}
.rounded-5 {
border-radius: 30px;
}
.bg-white {
background: var(--mud-palette-surface) !important;
}
.appName {
margin-top: 15px;
font-size: large;
font-weight: 900;
color: var(--mud-palette-primary)
}
.button-login {
text-align: center;
border: 2px solid var(--mud-palette-primary);
background-color: var(--mud-palette-primary);
border-radius: 25px;
padding: .3rem 2rem;
width: 100%;
font-weight: 700;
color: var(--mud-palette-appbar-text);
}
.login-footer {
display: flex;
align-items: center;
justify-content: flex-end;
}
.login-footer span {
font-size: 9px;
color: var(--mud-palette-gray-darker);
}
.login-footer img {
height: 15px;
margin-left: 4px;
}

View File

@@ -1,4 +1,5 @@
@page "/PersonalInfo"
@attribute [Authorize]
@using Template.Shared.Components.Layout
<HeaderLayout Title="Profilo" />

View File

@@ -1,4 +1,5 @@
@page "/Users"
@attribute [Authorize]
@using Template.Shared.Components.Layout
<HeaderLayout Title="Contatti" />

View File

@@ -1,6 +1,46 @@
<Router AppAssembly="@typeof(Routes).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
</Router>
@inject NavigationManager NavigationManager
<ErrorBoundary @ref="ErrorBoundary">
<ChildContent>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Routes).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
<Authorizing>
<p>Authorizing page</p>
</Authorizing>
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
NavigationManager.NavigateTo("/login");
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView>
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
</ChildContent>
<ErrorContent>
@* <ExceptionModal @ref="ExceptionModal"
Exception="@context"
ErrorBoundary="@ErrorBoundary"
OnRetry="() => ErrorBoundary?.Recover()"/> *@
</ErrorContent>
</ErrorBoundary>
@code {
private ErrorBoundary? ErrorBoundary { get; set; }
// private ExceptionModal ExceptionModal { get; set; }
}

View File

@@ -1,12 +1,14 @@
<div class="activity-card @Type">
<div class="activity-hours-section">
<span class="activity-hours">14:00</span>
<MudChip T="string" Icon="@IconConstants.Chip.Time" Color="Color.Dark" Size="Size.Small">1h</MudChip>
</div>
<div class="activity-card @Type shadow box-area">
<div class="activity-left-section">
<div class="activity-hours-section">
<span class="activity-hours">14:00</span>
<MudChip T="string" Icon="@IconConstants.Chip.Time" Color="Color.Dark" Size="Size.Small">1h</MudChip>
</div>
<div class="activity-body-section">
<span class="activity-title">Format</span>
<span class="activity-subtitle">Preparazione preventivo</span>
<div class="activity-body-section">
<span class="activity-title">Format</span>
<span class="activity-subtitle">Preparazione preventivo</span>
</div>
</div>
<div class="activity-info-section">

View File

@@ -1,5 +1,4 @@
.activity-card {
background: var(--mud-palette-background-gray);
width: 100%;
display: flex;
flex-direction: row;
@@ -16,6 +15,11 @@
.activity-card.commessa { border-left: 5px solid var(--mud-palette-warning); }
.activity-left-section {
display: flex;
align-items: center;
}
.activity-hours-section {
width: min-content;
display: flex;
@@ -29,7 +33,7 @@
.activity-body-section {
width: fit-content;
margin: 0 .5rem;
margin: 0 1rem;
display: flex;
flex-direction: column;
}