Add password changing
This commit is contained in:
25
Hcs.WebApp/Services/IdentityService.cs
Normal file
25
Hcs.WebApp/Services/IdentityService.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Hcs.WebApp.Services
|
||||
{
|
||||
public class IdentityService(NavigationManager navigationManager, IHttpClientFactory factory)
|
||||
{
|
||||
private readonly Uri baseUri = new($"{navigationManager.BaseUri}identity/");
|
||||
private readonly HttpClient httpClient = factory.CreateClient("WithIdentity");
|
||||
|
||||
public async Task ChangePassword(string oldPassword, string newPassword)
|
||||
{
|
||||
var uri = new Uri($"{baseUri}change-password");
|
||||
var content = new FormUrlEncodedContent(new Dictionary<string, string> {
|
||||
{ "oldPassword", oldPassword },
|
||||
{ "newPassword", newPassword }
|
||||
});
|
||||
var response = await httpClient.PostAsync(uri, content);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var message = await response.Content.ReadAsStringAsync();
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user