Creata pagina login con Syncfusion
This commit is contained in:
@@ -4,125 +4,350 @@
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using SmartDB.Data
|
||||
@using Syncfusion.Blazor.Inputs
|
||||
@using Syncfusion.Blazor.Buttons
|
||||
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject ILogger<Login> Logger
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IdentityRedirectManager RedirectManager
|
||||
|
||||
<PageTitle>Log in</PageTitle>
|
||||
<PageTitle>Accedi - SmartDB</PageTitle>
|
||||
|
||||
<h1>Log in</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<section>
|
||||
<StatusMessage Message="@errorMessage" />
|
||||
<EditForm Model="Input" method="post" OnValidSubmit="LoginUser" FormName="login">
|
||||
<div class="login-container">
|
||||
<style>
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
.login-wrapper {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
padding: 3rem 2.5rem;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.login-logo {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
color: #667eea;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.login-title {
|
||||
font-size: 1.75rem;
|
||||
color: #333;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.login-subtitle {
|
||||
font-size: 0.95rem;
|
||||
color: #888;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.form-group-custom {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.form-group-custom label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
::deep .e-input-group {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
::deep .e-input-group input.e-field {
|
||||
border: 2px solid #e0e0e0 !important;
|
||||
border-radius: 8px !important;
|
||||
padding: 0.75rem 1rem !important;
|
||||
font-size: 0.95rem !important;
|
||||
transition: all 0.3s ease !important;
|
||||
}
|
||||
|
||||
::deep .e-input-group input.e-field:focus {
|
||||
border-color: #667eea !important;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
||||
}
|
||||
|
||||
::deep .e-checkbox-wrapper {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
::deep .e-checkbox-wrapper label {
|
||||
color: #666 !important;
|
||||
font-size: 0.9rem !important;
|
||||
}
|
||||
|
||||
.login-button {
|
||||
width: 100%;
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
::deep .e-btn {
|
||||
border-radius: 8px !important;
|
||||
font-weight: 600 !important;
|
||||
text-transform: uppercase !important;
|
||||
letter-spacing: 0.5px !important;
|
||||
transition: all 0.3s ease !important;
|
||||
border: none !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
::deep .e-btn.e-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
||||
padding: 0.75rem 1.5rem !important;
|
||||
font-size: 0.95rem !important;
|
||||
min-height: 48px !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
::deep .e-btn.e-primary:hover:not(:disabled) {
|
||||
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4) !important;
|
||||
transform: translateY(-2px) !important;
|
||||
}
|
||||
|
||||
::deep .e-btn.e-primary:disabled {
|
||||
opacity: 0.7 !important;
|
||||
cursor: not-allowed !important;
|
||||
}
|
||||
|
||||
.login-links {
|
||||
text-align: center;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.login-links a {
|
||||
color: #667eea;
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.login-links a:hover {
|
||||
color: #764ba2;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.alert-custom {
|
||||
border-radius: 8px;
|
||||
margin-bottom: 1.5rem;
|
||||
border: none;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.alert-danger-custom {
|
||||
background-color: #fee;
|
||||
color: #c33;
|
||||
border-left: 4px solid #c33;
|
||||
}
|
||||
|
||||
.validation-error {
|
||||
color: #d32f2f;
|
||||
font-size: 0.8rem;
|
||||
margin-top: 0.3rem;
|
||||
}
|
||||
|
||||
.spinner-custom {
|
||||
display: inline-block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
border-top-color: white;
|
||||
animation: spin 1s ease-in-out infinite;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
@@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.login-divider {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 2rem 0;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.login-divider::before,
|
||||
.login-divider::after {
|
||||
content: '';
|
||||
flex: 1;
|
||||
height: 1px;
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
||||
.login-divider span {
|
||||
padding: 0 1rem;
|
||||
font-size: 0.85rem;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="login-wrapper">
|
||||
<div class="login-card">
|
||||
<div class="login-header">
|
||||
<div class="login-logo">🔐</div>
|
||||
<h1 class="login-title">SmartDB</h1>
|
||||
<p class="login-subtitle">Accedi al tuo account</p>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
<div class="alert alert-custom alert-danger-custom">
|
||||
<strong>Errore!</strong> @errorMessage
|
||||
</div>
|
||||
}
|
||||
|
||||
<EditForm Model="Input" FormName="login" OnValidSubmit="LoginUser">
|
||||
<DataAnnotationsValidator />
|
||||
<h2>Use a local account to log in.</h2>
|
||||
<hr />
|
||||
<ValidationSummary class="text-danger" role="alert" />
|
||||
<div class="form-floating mb-3">
|
||||
<InputText @bind-Value="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<ValidationMessage For="() => Input.Email" class="text-danger" />
|
||||
|
||||
<div class="form-group-custom">
|
||||
<label for="email">Email</label>
|
||||
<SfTextBox @bind-Value="Input.Email"
|
||||
id="email"
|
||||
Placeholder="name@example.com"
|
||||
CssClass="form-control-sf"
|
||||
ShowClearButton="true">
|
||||
</SfTextBox>
|
||||
<ValidationMessage For="() => Input.Email" class="validation-error" />
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<InputText type="password" @bind-Value="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" placeholder="password" />
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<ValidationMessage For="() => Input.Password" class="text-danger" />
|
||||
|
||||
<div class="form-group-custom">
|
||||
<label for="password">Password</label>
|
||||
<SfTextBox @bind-Value="Input.Password"
|
||||
id="password"
|
||||
Placeholder="Inserisci la tua password"
|
||||
CssClass="form-control-sf"
|
||||
TextMode="InputType.Password"
|
||||
ShowClearButton="true">
|
||||
</SfTextBox>
|
||||
<ValidationMessage For="() => Input.Password" class="validation-error" />
|
||||
</div>
|
||||
<div class="checkbox mb-3">
|
||||
<label class="form-label">
|
||||
<InputCheckbox @bind-Value="Input.RememberMe" class="darker-border-checkbox form-check-input" />
|
||||
Remember me
|
||||
</label>
|
||||
|
||||
<div class="form-group-custom">
|
||||
<SfCheckBox @bind-Checked="Input.RememberMe"
|
||||
Label="Ricordami"
|
||||
CssClass="remember-me-checkbox">
|
||||
</SfCheckBox>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
|
||||
|
||||
<div class="login-button">
|
||||
<SfButton IconCss="e-icon-search"
|
||||
IsPrimary="true"
|
||||
Disabled="@isSubmitting"
|
||||
OnClick="async () => await LoginUser()">
|
||||
@if (isSubmitting)
|
||||
{
|
||||
<span class="spinner-custom"></span>
|
||||
<span>Accesso in corso...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Accedi</span>
|
||||
}
|
||||
</SfButton>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
<div class="login-divider">
|
||||
<span>Supporto</span>
|
||||
</div>
|
||||
|
||||
<div class="login-links">
|
||||
<p>
|
||||
<a href="Account/ForgotPassword">Forgot your password?</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="@(NavigationManager.GetUriWithQueryParameters("Account/Register", new Dictionary<string, object?> { ["ReturnUrl"] = ReturnUrl }))">Register as a new user</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="Account/ResendEmailConfirmation">Resend email confirmation</a>
|
||||
<a href="Account/ForgotPassword">Password dimenticata?</a>
|
||||
</p>
|
||||
</div>
|
||||
</EditForm>
|
||||
</section>
|
||||
</div>
|
||||
<div class="col-md-6 col-md-offset-2">
|
||||
<section>
|
||||
<h3>Use another service to log in.</h3>
|
||||
<hr />
|
||||
<ExternalLoginPicker />
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string? errorMessage;
|
||||
private bool isSubmitting = false;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
private InputModel Input { get; set; } = new();
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
private string? ReturnUrl { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (HttpMethods.IsGet(HttpContext.Request.Method))
|
||||
{
|
||||
// Clear the existing external cookie to ensure a clean login process
|
||||
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoginUser()
|
||||
{
|
||||
// This doesn't count login failures towards account lockout
|
||||
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
|
||||
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
|
||||
if (result.Succeeded)
|
||||
isSubmitting = true;
|
||||
errorMessage = null;
|
||||
|
||||
try
|
||||
{
|
||||
Logger.LogInformation("User logged in.");
|
||||
RedirectManager.RedirectTo(ReturnUrl);
|
||||
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
RedirectManager.RedirectTo("/");
|
||||
}
|
||||
else if (result.IsLockedOut)
|
||||
{
|
||||
RedirectManager.RedirectTo("Account/Lockout");
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = "Email o password non validi. Riprova.";
|
||||
}
|
||||
}
|
||||
else if (result.RequiresTwoFactor)
|
||||
catch (Exception ex)
|
||||
{
|
||||
RedirectManager.RedirectTo(
|
||||
"Account/LoginWith2fa",
|
||||
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
|
||||
Logger.LogError(ex, "Errore durante il login");
|
||||
errorMessage = "Errore durante l'accesso. Riprova più tardi.";
|
||||
}
|
||||
else if (result.IsLockedOut)
|
||||
finally
|
||||
{
|
||||
Logger.LogWarning("User account locked out.");
|
||||
RedirectManager.RedirectTo("Account/Lockout");
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = "Error: Invalid login attempt.";
|
||||
isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class InputModel
|
||||
private class InputModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[Required(ErrorMessage = "L'email è obbligatoria")]
|
||||
[EmailAddress(ErrorMessage = "Inserisci un'email valida")]
|
||||
public string Email { get; set; } = "";
|
||||
|
||||
[Required]
|
||||
[Required(ErrorMessage = "La password è obbligatoria")]
|
||||
[DataType(DataType.Password)]
|
||||
public string Password { get; set; } = "";
|
||||
|
||||
[Display(Name = "Remember me?")]
|
||||
[Display(Name = "Ricordami?")]
|
||||
public bool RememberMe { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user