updating auth

arthur_usercookies
Arthur VALIN 2 years ago
parent 4b31e3ff78
commit 7a0a4e4204

@ -5,6 +5,8 @@ using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Components;
using CraftSharp.Models;
using CraftSharp.Services;
using Newtonsoft.Json;
using System.Net.Http;
namespace CraftSharp.Pages
{
@ -16,14 +18,22 @@ namespace CraftSharp.Pages
[Inject]
public NavigationManager NavigationManager { get; set; }
[Inject]
public HttpClient httpClient { get; set; }
private string error { get; set; }
private InscriptionModel registerRequest { get; set; } = new InscriptionModel();
private async Task OnSubmit()
{
await AuthStateProvider.Register(registerRequest);
NavigationManager.NavigateTo("index");
await AuthStateProvider.Register(registerRequest);
var stringified = JsonConvert.SerializeObject(new ConnexionModel() {
Password=registerRequest.Password,
UserName=registerRequest.UserName}
);
var response = await httpClient.PostAsJsonAsync($"{NavigationManager.BaseUri}User/SetUser", stringified);
NavigationManager.NavigateTo("index");
}
}

@ -3,6 +3,7 @@ using CraftSharp.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Localization;
using System.Net.Http;
namespace CraftSharp.Shared
@ -18,6 +19,9 @@ namespace CraftSharp.Shared
[Inject]
public NavigationManager NavigationManager { get; set; }
[Inject]
public HttpClient httpClient { get; set; }
[CascadingParameter]
private Task<AuthenticationState> AuthenticationState { get; set; }
@ -46,6 +50,8 @@ namespace CraftSharp.Shared
private async Task LogoutClick()
{
await AuthStateProvider.Logout();
await httpClient.DeleteAsync($"{NavigationManager.BaseUri}User/DeleteUser");
NavigationManager.NavigateTo("/inscription");
}
}

Loading…
Cancel
Save