@page "/login/{role}"
@using HealthcareManagerUI.Models
@using HealthcareManagerUI.Services.Authentication
@using HealthcareManagerUI.Components.Layout
@layout AuthLayout
@inject IAuthenticationService AuthenticationService
@inject NavigationManager NavigationManager
Login
Login
Register
Reset Password
@code {
[SupplyParameterFromForm]
public UserLoginModel? userLoginModel { get; set; }
protected override void OnInitialized()
{
userLoginModel ??= new();
}
[Parameter] public string Role { get; set; }
private string errorMessage { get; set; }
private void ClearErrorMessage()
{
errorMessage = string.Empty;
}
private async Task HandleLogin()
{
var response = Role switch
{
"doctor" => await AuthenticationService.LoginDoctor(userLoginModel),
"patient" => await AuthenticationService.LoginPatient(userLoginModel),
_ => null
};
if (response.StatusCode >= 200 && response.StatusCode <= 399)
{
NavigationManager.NavigateTo("/dashboard");
}
else
{
errorMessage = response.Message;
}
}
}