jwt v1.0
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
@page "/login/{role}"
|
||||
@using HealthcareManagerUI.Models
|
||||
@using HealthcareManagerUI.Services.Authentication
|
||||
@using HealthcareManagerUI.Components.Layout
|
||||
|
||||
@layout AuthLayout
|
||||
|
||||
@inject IAuthenticationService AuthenticationService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<head>
|
||||
<title>Login</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</head>
|
||||
<link rel="stylesheet" href="/LoginPage.css" />
|
||||
<link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css" />
|
||||
|
||||
<EditForm Model="userLoginModel" OnValidSubmit="@HandleLogin" FormName="LoginForm" class="login-form container mt-5">
|
||||
<DataAnnotationsValidator/>
|
||||
<ValidationSummary/>
|
||||
|
||||
<div class="card shadow-lg">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-center mb-3">Login</h3>
|
||||
<div class="form-group mb-3">
|
||||
<InputText id="email" class="form-control" placeholder="Email" @bind-Value="userLoginModel!.Email"></InputText>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<InputText id="password" class="form-control" type="password" placeholder="Password" @bind-Value="userLoginModel!.Password"></InputText>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100 mb-3">Log In</button>
|
||||
<div class="button-container">
|
||||
<NavLink class="btn btn-secondary m-2" href="@($"/register/{Role}")">Register</NavLink>
|
||||
<NavLink class="btn btn-secondary m-2" href="@($"/reset-password/{Role}")">Reset Password</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<AlertMessage ErrorMessage="@errorMessage" />
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user