generated from Integry/Template_NetMauiBlazorHybrid
116 lines
4.0 KiB
Plaintext
116 lines
4.0 KiB
Plaintext
@page "/login"
|
|
@using salesbook.Shared.Components.Layout.Spinner
|
|
@using salesbook.Shared.Core.Interface
|
|
@using salesbook.Shared.Core.Interface.System.Network
|
|
@using salesbook.Shared.Core.Services
|
|
@inject IUserAccountService UserAccountService
|
|
@inject AppAuthenticationStateProvider AuthenticationStateProvider
|
|
@inject INetworkService NetworkService
|
|
|
|
@if (Spinner)
|
|
{
|
|
<SpinnerLayout/>
|
|
}
|
|
else
|
|
{
|
|
<div class="login-page">
|
|
<div class="container container-top-logo">
|
|
<img src="_content/salesbook.Shared/images/salesbook-marchio_vers.positiva.svg" class="logo" alt="sales book">
|
|
</div>
|
|
<div class="container container-login">
|
|
<div class="login-form-container">
|
|
<div class="input-group">
|
|
<MudTextField @bind-Value="UserData.Username" Label="Username" Variant="Variant.Outlined"/>
|
|
</div>
|
|
<div class="input-group">
|
|
<MudTextField InputType="@_passwordInput" @bind-Value="UserData.Password" Label="Password" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@_passwordInputIcon" OnAdornmentClick="ShowPassword" AdornmentAriaLabel="Show Password"/>
|
|
</div>
|
|
<div class="input-group mb-2">
|
|
<MudTextField @bind-Value="UserData.CodHash" Label="Profilo azienda" Variant="Variant.Outlined"/>
|
|
</div>
|
|
|
|
<MudButton Disabled="@(!NetworkService.ConnectionAvailable)" OnClick="SignInUser" Color="Color.Primary" Variant="Variant.Filled">Login</MudButton>
|
|
@if (_attemptFailed)
|
|
{
|
|
<MudAlert Class="my-3" Dense="true" Severity="Severity.Error" Variant="Variant.Filled">@ErrorMessage</MudAlert>
|
|
}
|
|
</div>
|
|
|
|
<div class="my-4 login-footer">
|
|
<span>Powered by</span>
|
|
<img src="_content/salesbook.Shared/images/logoIntegry.svg" class="img-fluid" alt="Integry">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private SignIn UserData { get; } = new();
|
|
private bool Spinner { get; set; }
|
|
private string ErrorMessage { get; set; } = "";
|
|
private bool _attemptFailed;
|
|
|
|
private bool _isShow;
|
|
private InputType _passwordInput = InputType.Password;
|
|
private string _passwordInputIcon = Icons.Material.Rounded.VisibilityOff;
|
|
|
|
private void ShowPassword()
|
|
{
|
|
@if (_isShow)
|
|
{
|
|
_isShow = false;
|
|
_passwordInputIcon = Icons.Material.Rounded.VisibilityOff;
|
|
_passwordInput = InputType.Password;
|
|
}
|
|
else
|
|
{
|
|
_isShow = true;
|
|
_passwordInputIcon = Icons.Material.Rounded.Visibility;
|
|
_passwordInput = InputType.Text;
|
|
}
|
|
}
|
|
|
|
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; }
|
|
}
|
|
|
|
} |