jwt v1.0
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
using HealthcareManagerUI.Models;
|
||||
using HealthcareManagerUI.Services.Http;
|
||||
namespace HealthcareManagerUI.Services.Authentication;
|
||||
|
||||
// In AuthenticationService.cs
|
||||
public class AuthenticationService : IAuthenticationService
|
||||
{
|
||||
private readonly IHttpService _httpService;
|
||||
private readonly string _apiUrl = "http://localhost:5151/api";
|
||||
|
||||
public AuthenticationService(IHttpService httpService)
|
||||
{
|
||||
_httpService = httpService;
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> LoginDoctor(UserLoginModel userLoginModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpService.PostAsync<BaseResponse>($"{_apiUrl}/Doctors/login", userLoginModel);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Data = null,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> LoginPatient(UserLoginModel userLoginModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpService.PostAsync<BaseResponse>($"{_apiUrl}/Patients/login", userLoginModel);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new BaseResponse {
|
||||
StatusCode = 400,
|
||||
Data = null,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> RegisterDoctor(UserRegisterModel userRegistrationModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpService.PostAsync<BaseResponse>($"{_apiUrl}/Doctors/register", userRegistrationModel);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Data = null,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> RegisterPatient(UserRegisterModel userRegisterModel)
|
||||
{
|
||||
var patientRegisterDto = new PatientRegisterModel
|
||||
{
|
||||
Name = userRegisterModel.Name,
|
||||
Email = userRegisterModel.Email,
|
||||
Password = userRegisterModel.Password
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _httpService.PostAsync<BaseResponse>($"{_apiUrl}/Patients/register", userRegisterModel);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Data = null,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> ResetDoctorPassword(UserRegisterModel userResetPasswordModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpService.PostAsync<BaseResponse>($"{_apiUrl}/Doctors/reset_password", userResetPasswordModel);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Data = null,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> ResetPatientPassword(UserRegisterModel userResetPasswordModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpService.PostAsync<BaseResponse>($"{_apiUrl}/Patients/reset_password", userResetPasswordModel);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Data = null,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user