finalizare 1.0
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
@page "/goodbye"
|
||||
@layout AuthLayout
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<h3>Goodbye</h3>
|
||||
|
||||
<div class="card mt-4">
|
||||
<div class="card-body">
|
||||
<p>Thank you for using our service. We're sorry to see you go.</p>
|
||||
<button class="btn btn-primary" @onclick="RedirectToHome">Go to Home Page</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
private void RedirectToHome()
|
||||
{
|
||||
NavigationManager.NavigateTo("/");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
@page "/"
|
||||
@layout AuthLayout
|
||||
|
||||
<h1>Welcome to HealthcareManagerApp</h1>
|
||||
<p>Your Health, Our Priority.</p>
|
||||
|
||||
<p>At HealthcareManagerApp, we believe in providing the best care for our patients and ensuring seamless operations for our healthcare providers.</p>
|
||||
<p>Join us in our mission to make healthcare accessible and efficient for everyone.</p>
|
||||
|
||||
<p>
|
||||
<a class="btn btn-primary" href="/login">Login</a>
|
||||
<a class="btn btn-secondary" href="/register">Register</a>
|
||||
</p>
|
||||
@@ -0,0 +1,81 @@
|
||||
@page "/login"
|
||||
@inject IAuthenticationService AuthenticationService
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@layout AuthLayout
|
||||
<h3>Login</h3>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger mt-2">@_errorMessage</div>
|
||||
}
|
||||
|
||||
<EditForm Model="_loginModel" OnValidSubmit="HandleLogin">
|
||||
<div class="form-group">
|
||||
<label>Email:</label>
|
||||
<InputText class="form-control" @bind-Value="_loginModel.Email"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password:</label>
|
||||
<InputText class="form-control" @bind-Value="_loginModel.Password" type="password"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
private readonly UserLoginModel _loginModel = new();
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
private async Task HandleLogin()
|
||||
{
|
||||
_errorMessage = string.Empty;
|
||||
var response = await AuthenticationService.Login(_loginModel);
|
||||
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
var token = await AuthenticationService.GetAuthToken();
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwtToken = handler.ReadJwtToken(token);
|
||||
var role = jwtToken.Claims.FirstOrDefault(c => c.Type == "role")?.Value;
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case UserRoles.Admin:
|
||||
Navigation.NavigateTo("/admin/dashboard", true);
|
||||
break;
|
||||
case UserRoles.Doctor:
|
||||
Navigation.NavigateTo("/doctor/dashboard", true);
|
||||
break;
|
||||
case UserRoles.Patient:
|
||||
Navigation.NavigateTo("/patient/dashboard", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = response.Message; // Display error message
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var token = await AuthenticationService.GetAuthToken();
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwtToken = handler.ReadJwtToken(token);
|
||||
var role = jwtToken.Claims.FirstOrDefault(c => c.Type == "role")?.Value;
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case UserRoles.Admin:
|
||||
Navigation.NavigateTo("/admin/dashboard", true);
|
||||
break;
|
||||
case UserRoles.Doctor:
|
||||
Navigation.NavigateTo("/doctor/dashboard", true);
|
||||
break;
|
||||
case UserRoles.Patient:
|
||||
Navigation.NavigateTo("/patient/dashboard", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
@page "/register"
|
||||
@inject NavigationManager Navigation
|
||||
@inject IAuthenticationService AuthenticationService
|
||||
@layout AuthLayout
|
||||
|
||||
<h3>Register</h3>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger mt-2">@_errorMessage</div>
|
||||
}
|
||||
|
||||
|
||||
<EditForm Model="_registerModel" OnValidSubmit="HandleRegister">
|
||||
<div class="form-group">
|
||||
<label>Name:</label>
|
||||
<InputText class="form-control" @bind-Value="_registerModel.Name"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Email:</label>
|
||||
<InputText class="form-control" @bind-Value="_registerModel.Email"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password:</label>
|
||||
<InputText class="form-control" @bind-Value="_registerModel.Password" type="password"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Role:</label>
|
||||
<InputSelect class="form-control" @bind-Value="_registerModel.Role">
|
||||
<option value="">Select a role</option>
|
||||
<option value="Doctor">Doctor</option>
|
||||
<option value="Patient">Patient</option>
|
||||
</InputSelect>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Register</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
private readonly UserRegisterModel _registerModel = new();
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
private async Task HandleRegister()
|
||||
{
|
||||
_errorMessage = string.Empty;
|
||||
var response = await AuthenticationService.Register(_registerModel);
|
||||
|
||||
if (response.StatusCode == 201)
|
||||
{
|
||||
// Registration successful, navigate to login page
|
||||
Navigation.NavigateTo("/login", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = response.Message; // Display error message
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var token = await AuthenticationService.GetAuthToken();
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwtToken = handler.ReadJwtToken(token);
|
||||
var role = jwtToken.Claims.FirstOrDefault(c => c.Type == "role")?.Value;
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case UserRoles.Admin:
|
||||
Navigation.NavigateTo("/admin/dashboard", true);
|
||||
break;
|
||||
case UserRoles.Doctor:
|
||||
Navigation.NavigateTo("/doctor/dashboard", true);
|
||||
break;
|
||||
case UserRoles.Patient:
|
||||
Navigation.NavigateTo("/patient/dashboard", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
@page "/reset-password"
|
||||
@inject IAuthenticationService AuthenticationService
|
||||
@inject NavigationManager Navigation
|
||||
@layout AuthLayout
|
||||
|
||||
<h3>Reset Password</h3>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger mt-2">@_errorMessage</div>
|
||||
}
|
||||
|
||||
<EditForm Model="_resetPasswordModel" OnValidSubmit="HandleResetPassword">
|
||||
<div class="form-group">
|
||||
<label>Email:</label>
|
||||
<InputText class="form-control" @bind-Value="_resetPasswordModel.Email"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>New Password:</label>
|
||||
<InputText class="form-control" @bind-Value="_resetPasswordModel.Password" type="password"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Reset Password</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
private readonly ResetPasswordModel _resetPasswordModel = new();
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
private async Task HandleResetPassword()
|
||||
{
|
||||
_errorMessage = string.Empty;
|
||||
var response = await AuthenticationService.ResetPassword(_resetPasswordModel);
|
||||
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
Navigation.NavigateTo("/login", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorMessage = response.Message; // Display error message
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user