summary refs log tree commit diff
path: root/testFrontend
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-01 09:23:16 +0200
committerRory& <root@rory.gay>2025-06-01 09:23:16 +0200
commit073248777a6414505b1df7f65a0cb1dcf5c44118 (patch)
tree35c0c82c1841ee4c7434ada3c89c3e702561361a /testFrontend
parentLogin, delete user (diff)
downloadnodejs-final-assignment-073248777a6414505b1df7f65a0cb1dcf5c44118.tar.xz
Update test client
Diffstat (limited to 'testFrontend')
-rw-r--r--testFrontend/SafeNSound.Frontend/Pages/Auth.razor9
-rw-r--r--testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs31
-rw-r--r--testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs2
3 files changed, 29 insertions, 13 deletions
diff --git a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor

index 6c28bf1..3db77a1 100644 --- a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor +++ b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor
@@ -1,6 +1,5 @@ @page "/Auth" - <h1>Auth</h1> <span>Username (L?, R): </span> @@ -8,7 +7,7 @@ <span>Email (L? R): </span> <FancyTextBox @bind-Value="@Email"/><br/> <span>Password (L, R): </span> -<FancyTextBox @bind-Value="@Password"/><br/> +<FancyTextBox @bind-Value="@Password" IsPassword="true" /><br/> <span>Type (R): </span> <FancyTextBox @bind-Value="@UserType"/><span> (one of user|monitor|admin)</span><br/> <LinkButton OnClick="@Randomise">Randomise</LinkButton> @@ -46,7 +45,7 @@ private async Task Randomise() { Username = Guid.NewGuid().ToString(); - Email = Guid.NewGuid().ToString() + "@example.com"; + Email = Guid.NewGuid() + "@example.com"; Password = Guid.NewGuid().ToString(); UserType = Random.Shared.GetItems(["user", "monitor", "admin"], 1)[0]; StateHasChanged(); @@ -56,7 +55,7 @@ Result = null; Exception = null; try { - Result = await Authentication.Register(new() { + await Authentication.Register(new() { Username = Username, Password = Password, Email = Email, @@ -91,7 +90,7 @@ Result = null; Exception = null; try { - Result = await Authentication.Delete(new() { + await Authentication.Delete(new() { Username = Username, Password = Password, Email = Email diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
index cbff880..f63d8b0 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
@@ -1,15 +1,16 @@ -using System.Text.Json.Serialization; +using System.Net.Http.Json; +using System.Text.Json.Serialization; namespace SafeNSound.Sdk; public class SafeNSoundAuthentication(SafeNSoundConfiguration config) { - public async Task<SafeNSoundAuthResult> Register(RegisterDto registerDto) { + public async Task Register(RegisterDto registerDto) { var hc = new WrappedHttpClient() { BaseAddress = new Uri(config.BaseUri) }; var res = await hc.PostAsJsonAsync("/auth/register", registerDto); - return null!; + res.EnsureSuccessStatusCode(); } public async Task<SafeNSoundAuthResult> Login(AuthDto authDto) { @@ -18,17 +19,16 @@ public class SafeNSoundAuthentication(SafeNSoundConfiguration config) { }; var res = await hc.PostAsJsonAsync("/auth/login", authDto); - return null!; + return (await res.Content.ReadFromJsonAsync<SafeNSoundAuthResult>())!; } - public async Task<SafeNSoundAuthResult> Delete(AuthDto authDto) { + public async Task Delete(AuthDto authDto) { var hc = new WrappedHttpClient() { BaseAddress = new Uri(config.BaseUri) }; var res = await hc.DeleteAsJsonAsync("/auth/delete", authDto); res.EnsureSuccessStatusCode(); - return null!; } } @@ -57,4 +57,21 @@ public class AuthDto { public string Email { get; set; } = string.Empty; } -public class SafeNSoundAuthResult { } \ No newline at end of file +public class WhoAmI { + [JsonPropertyName("userId")] + public required string UserId { get; set; } + + [JsonPropertyName("username")] + public required string UserName { get; set; } + + [JsonPropertyName("deviceId")] + public required string DeviceId { get; set; } + + [JsonPropertyName("type")] + public required string UserType { get; set; } +} + +public class SafeNSoundAuthResult : WhoAmI { + [JsonPropertyName("accessToken")] + public required string AccessToken { get; set; } +} \ No newline at end of file diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
index 7a7023c..dee3913 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
@@ -1,6 +1,6 @@ namespace SafeNSound.Sdk; -public class SafeNSoundClient +public class SafeNSoundClient(SafeNSoundConfiguration config) { } \ No newline at end of file