diff --git a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor
index 533fc01..6c28bf1 100644
--- a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor
+++ b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor
@@ -11,8 +11,10 @@
<FancyTextBox @bind-Value="@Password"/><br/>
<span>Type (R): </span>
<FancyTextBox @bind-Value="@UserType"/><span> (one of user|monitor|admin)</span><br/>
-<LinkButton OnClick="Login">Login</LinkButton>
-<LinkButton OnClick="Register">Register</LinkButton>
+<LinkButton OnClick="@Randomise">Randomise</LinkButton>
+<LinkButton OnClick="@Register">Register</LinkButton>
+<LinkButton OnClick="@Login">Login</LinkButton>
+<LinkButton OnClick="@Delete">Delete</LinkButton>
<br/><br/>
@if (Exception != null) {
@@ -34,14 +36,22 @@
}
@code {
- private string Username { get; set; } = "";
- private string Email { get; set; } = "";
- private string Password { get; set; } = "";
+ private string Username { get; set; } = String.Empty;
+ private string Email { get; set; } = String.Empty;
+ private string Password { get; set; } = String.Empty;
private string UserType { get; set; } = "";
private Exception? Exception { get; set; }
private object? Result { get; set; }
+ private async Task Randomise() {
+ Username = Guid.NewGuid().ToString();
+ Email = Guid.NewGuid().ToString() + "@example.com";
+ Password = Guid.NewGuid().ToString();
+ UserType = Random.Shared.GetItems(["user", "monitor", "admin"], 1)[0];
+ StateHasChanged();
+ }
+
private async Task Register() {
Result = null;
Exception = null;
@@ -56,13 +66,42 @@
catch (Exception ex) {
Exception = ex;
}
- finally {
- StateHasChanged();
+
+ StateHasChanged();
+ }
+
+ private async Task Login() {
+ Result = null;
+ Exception = null;
+ try {
+ Result = await Authentication.Login(new() {
+ Username = Username,
+ Password = Password,
+ Email = Email
+ });
+ }
+ catch (Exception ex) {
+ Exception = ex;
}
+
+ StateHasChanged();
}
- private Task Login() {
- throw new NotImplementedException();
+ private async Task Delete() {
+ Result = null;
+ Exception = null;
+ try {
+ Result = await Authentication.Delete(new() {
+ Username = Username,
+ Password = Password,
+ Email = Email
+ });
+ }
+ catch (Exception ex) {
+ Exception = ex;
+ }
+
+ StateHasChanged();
}
}
\ No newline at end of file
diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
index 429e93c..cbff880 100644
--- a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
+++ b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
@@ -3,11 +3,6 @@
namespace SafeNSound.Sdk;
public class SafeNSoundAuthentication(SafeNSoundConfiguration config) {
- // public async Task<SafeNSoundAuthResult> Login(string username, string password)
- // {
-
- // }
-
public async Task<SafeNSoundAuthResult> Register(RegisterDto registerDto) {
var hc = new WrappedHttpClient() {
BaseAddress = new Uri(config.BaseUri)
@@ -16,6 +11,25 @@ public class SafeNSoundAuthentication(SafeNSoundConfiguration config) {
var res = await hc.PostAsJsonAsync("/auth/register", registerDto);
return null!;
}
+
+ public async Task<SafeNSoundAuthResult> Login(AuthDto authDto) {
+ var hc = new WrappedHttpClient() {
+ BaseAddress = new Uri(config.BaseUri)
+ };
+
+ var res = await hc.PostAsJsonAsync("/auth/login", authDto);
+ return null!;
+ }
+
+ public async Task<SafeNSoundAuthResult> Delete(AuthDto authDto) {
+ var hc = new WrappedHttpClient() {
+ BaseAddress = new Uri(config.BaseUri)
+ };
+
+ var res = await hc.DeleteAsJsonAsync("/auth/delete", authDto);
+ res.EnsureSuccessStatusCode();
+ return null!;
+ }
}
public class RegisterDto {
@@ -32,4 +46,15 @@ public class RegisterDto {
public string UserType { get; set; } = string.Empty;
}
+public class AuthDto {
+ [JsonPropertyName("username")]
+ public string Username { get; set; } = string.Empty;
+
+ [JsonPropertyName("password")]
+ public string Password { get; set; } = string.Empty;
+
+ [JsonPropertyName("email")]
+ public string Email { get; set; } = string.Empty;
+}
+
public class SafeNSoundAuthResult { }
\ No newline at end of file
|