@* @page "/Auth" *@
@* *@
@*
Auth
*@
@* User:
*@
@* Username (L?, R): *@
@*
*@
@* Email (L? R): *@
@*
*@
@* Password (L, R): *@
@*
*@
@* Type (R): *@
@* (one of user|monitor|admin)
*@
@* Randomise *@
@* Register *@
@* Login *@
@* Who Am I *@
@* Delete *@
@* Register superadmin *@
@*
*@
@* *@
@* Monitor:
*@
@* User ID: *@
@*
*@
@* Get *@
@* Add *@
@* Remove *@
@*
*@
@* *@
@* Devices:
*@
@* @if (CurrentDevice is not null) { *@
@* Device ID: @CurrentDevice.Id
*@
@* Log in date: @CurrentDevice.CreatedAt
*@
@* Last seen: @CurrentDevice.LastSeen
*@
@* Device name: *@
@*
*@
@* Get *@
@* Update *@
@* Delete *@
@* Get all *@
@* } *@
@* *@
@* @if (Exception != null) { *@
@* *@
@*
Error: *@
@*
*@
@* @Exception *@
@*
*@
@*
*@
@* } *@
@* *@
@* @if (Result != null) { *@
@* *@
@*
Result: *@
@*
*@
@* @Result.ToJson(indent: true) *@
@*
*@
@*
*@
@* } *@
@* *@
@* @code { *@
@* *@
@* private RegisterDto AuthData { get; set; } = new() { *@
@* Username = string.Empty, *@
@* UserType = string.Empty, *@
@* Email = String.Empty, *@
@* Password = string.Empty *@
@* }; *@
@* *@
@* private DeviceDto? CurrentDevice { get; set; } *@
@* *@
@* private string TargetUserId { get; set; } = string.Empty; *@
@* *@
@* private Exception? Exception { get; set; } *@
@* private object? Result { get; set; } *@
@* *@
@* private async Task Randomise() { *@
@* AuthData.Username = Guid.NewGuid().ToString(); *@
@* AuthData.Email = Guid.NewGuid() + "@example.com"; *@
@* AuthData.Password = Guid.NewGuid().ToString(); *@
@* AuthData.UserType = Random.Shared.GetItems(["user", "monitor", "admin"], 1)[0]; *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task Register() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* await Authentication.Register(new() { *@
@* Username = AuthData.Username, *@
@* Password = AuthData.Password, *@
@* Email = AuthData.Email, *@
@* UserType = AuthData.UserType *@
@* }); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task Login() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* AuthResult result; *@
@* Result = result = await Authentication.Login(new() { *@
@* Username = AuthData.Username, *@
@* Password = AuthData.Password, *@
@* Email = AuthData.Email *@
@* }); *@
@* App.Client = new SafeNSoundClient(Config, result.AccessToken); *@
@* CurrentDevice = await App.Client.GetDevice( *@
@* (await App.Client.WhoAmI()).DeviceId *@
@* ); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task Delete() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* await Authentication.Delete(new() { *@
@* Username = AuthData.Username, *@
@* Password = AuthData.Password, *@
@* Email = AuthData.Email *@
@* }); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task WhoAmI() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* Result = await App.Client!.WhoAmI(); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task GetAssignedUsers() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* Result = await App.Client!.GetAssignedUsers(); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task AddAssignedUser() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* await App.Client!.AddAssignedUser(TargetUserId); *@
@* await GetAssignedUsers(); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task RemoveAssignedUser() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* await App.Client!.RemoveAssignedUser(TargetUserId); *@
@* await GetAssignedUsers(); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task MakeFullAdmin() { *@
@* Result = null; *@
@* Exception = null; *@
@* try { *@
@* AuthResult result; *@
@* RegisterDto auth = new() { *@
@* Username = Guid.NewGuid().ToString(), *@
@* Password = Guid.NewGuid().ToString(), *@
@* Email = Guid.NewGuid() + "@example.com", *@
@* UserType = "admin" *@
@* }; *@
@* await Authentication.Register(auth); *@
@* Result = result = await Authentication.Login(auth); *@
@* App.Client = new SafeNSoundClient(Config, result.AccessToken); *@
@* await App.Client.MonitorAllUsers(); *@
@* } *@
@* catch (Exception ex) { *@
@* Exception = ex; *@
@* } *@
@* *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task GetDevice() { *@
@* Result = CurrentDevice = await App.Client!.GetDevice(CurrentDevice!.Id!); *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* private async Task UpdateDevice() { *@
@* await App.Client!.UpdateDevice(CurrentDevice!.Id!, new() { *@
@* Name = CurrentDevice.Name *@
@* }); *@
@* await GetDevice(); *@
@* } *@
@* *@
@* private async Task DeleteDevice() { *@
@* await App.Client!.DeleteDevice(CurrentDevice!.Id!); *@
@* } *@
@* *@
@* private async Task GetAllDevices() { *@
@* Result = await App.Client!.GetDevices(); *@
@* StateHasChanged(); *@
@* } *@
@* *@
@* } *@