Migration to using System.Net.Http.Json; part one - functional migration
This commit is contained in:
@ -8,14 +8,14 @@ namespace Oqtane.Services
|
||||
{
|
||||
public class UserService : ServiceBase, IUserService
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
|
||||
private readonly SiteState _siteState;
|
||||
private readonly NavigationManager _navigationManager;
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public UserService(HttpClient http, SiteState siteState, NavigationManager navigationManager, ISiteService siteService)
|
||||
public UserService(HttpClient http, SiteState siteState, NavigationManager navigationManager, ISiteService siteService) : base(http)
|
||||
{
|
||||
_http = http;
|
||||
|
||||
_siteState = siteState;
|
||||
_navigationManager = navigationManager;
|
||||
_siteService = siteService;
|
||||
@ -28,12 +28,12 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<User> GetUserAsync(int userId, int siteId)
|
||||
{
|
||||
return await _http.GetJsonAsync<User>($"{Apiurl}/{userId.ToString()}?siteid={siteId.ToString()}");
|
||||
return await GetJsonAsync<User>($"{Apiurl}/{userId.ToString()}?siteid={siteId.ToString()}");
|
||||
}
|
||||
|
||||
public async Task<User> GetUserAsync(string username, int siteId)
|
||||
{
|
||||
return await _http.GetJsonAsync<User>($"{Apiurl}/name/{username}?siteid={siteId.ToString()}");
|
||||
return await GetJsonAsync<User>($"{Apiurl}/name/{username}?siteid={siteId.ToString()}");
|
||||
}
|
||||
|
||||
public async Task<User> AddUserAsync(User user)
|
||||
@ -47,7 +47,7 @@ namespace Oqtane.Services
|
||||
|
||||
try
|
||||
{
|
||||
return await _http.PostJsonAsync<User>(Apiurl, user);
|
||||
return await PostJsonAsync<User>(Apiurl, user);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -59,7 +59,7 @@ namespace Oqtane.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _http.PostJsonAsync<User>(CreateCrossTenantUrl(Apiurl, alias), user);
|
||||
return await PostJsonAsync<User>(CreateCrossTenantUrl(Apiurl, alias), user);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -69,37 +69,37 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<User> UpdateUserAsync(User user)
|
||||
{
|
||||
return await _http.PutJsonAsync<User>($"{Apiurl}/{user.UserId.ToString()}", user);
|
||||
return await PutJsonAsync<User>($"{Apiurl}/{user.UserId.ToString()}", user);
|
||||
}
|
||||
public async Task DeleteUserAsync(int userId)
|
||||
{
|
||||
await _http.DeleteAsync($"{Apiurl}/{userId.ToString()}");
|
||||
await DeleteAsync($"{Apiurl}/{userId.ToString()}");
|
||||
}
|
||||
|
||||
public async Task<User> LoginUserAsync(User user, bool setCookie, bool isPersistent)
|
||||
{
|
||||
return await _http.PostJsonAsync<User>($"{Apiurl}/login?setcookie={setCookie.ToString()}&persistent={isPersistent.ToString()}", user);
|
||||
return await PostJsonAsync<User>($"{Apiurl}/login?setcookie={setCookie.ToString()}&persistent={isPersistent.ToString()}", user);
|
||||
}
|
||||
|
||||
public async Task LogoutUserAsync(User user)
|
||||
{
|
||||
// best practices recommend post is preferrable to get for logout
|
||||
await _http.PostJsonAsync($"{Apiurl}/logout", user);
|
||||
await PostJsonAsync($"{Apiurl}/logout", user);
|
||||
}
|
||||
|
||||
public async Task<User> VerifyEmailAsync(User user, string token)
|
||||
{
|
||||
return await _http.PostJsonAsync<User>($"{Apiurl}/verify?token={token}", user);
|
||||
return await PostJsonAsync<User>($"{Apiurl}/verify?token={token}", user);
|
||||
}
|
||||
|
||||
public async Task ForgotPasswordAsync(User user)
|
||||
{
|
||||
await _http.PostJsonAsync($"{Apiurl}/forgot", user);
|
||||
await PostJsonAsync($"{Apiurl}/forgot", user);
|
||||
}
|
||||
|
||||
public async Task<User> ResetPasswordAsync(User user, string token)
|
||||
{
|
||||
return await _http.PostJsonAsync<User>($"{Apiurl}/reset?token={token}", user);
|
||||
return await PostJsonAsync<User>($"{Apiurl}/reset?token={token}", user);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user