You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
using HeartTrack.Models.Authentification;
|
|
using HeartTrack.Services.AuthentificationService;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
namespace HeartTrack.Pages.Authentification
|
|
{
|
|
public partial class Login
|
|
{
|
|
[Inject]
|
|
public CustomStateProvider AuthStateProvider { get; set; }
|
|
|
|
[Inject]
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
[Inject]
|
|
public IStringLocalizer<Login> Localizer { get; set; }
|
|
|
|
private string errorMessage { get; set; }
|
|
|
|
[Inject]
|
|
public ILogger<Login> Logger { get; set; }
|
|
|
|
private LoginRequest loginRequest { get; set; } = new LoginRequest();
|
|
|
|
private async Task OnSubmit()
|
|
{
|
|
errorMessage = null;
|
|
try
|
|
{
|
|
Logger.LogInformation($"Tentative de connexion pour l'utilisateur : {loginRequest.UserName}");
|
|
await Task.Run(() => AuthStateProvider.Login(loginRequest));
|
|
Logger.LogInformation($"L'utilisateur {loginRequest.UserName} s'est connecté avec succès");
|
|
NavigationManager.NavigateTo("");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorMessage = ex.Message;
|
|
Logger.LogError(ex, $"Échec de connexion pour l'utilisateur : {loginRequest.UserName}");
|
|
}
|
|
}
|
|
}
|
|
}
|