diff --git a/Flawless.Client/Service/Remote_Generated.cs b/Flawless.Client/Service/Remote_Generated.cs index aa919c6..416693a 100644 --- a/Flawless.Client/Service/Remote_Generated.cs +++ b/Flawless.Client/Service/Remote_Generated.cs @@ -18,6 +18,12 @@ namespace Flawless.Client.Remote [System.CodeDom.Compiler.GeneratedCode("Refitter", "1.5.5.0")] public partial interface IFlawlessServer { + /// A that completes when the request is finished. + /// Thrown when the request returns a non-success status code. + [Headers("Content-Type: application/json")] + [Post("/api/admin/add_user")] + Task AddUser([Body] RegisterRequest body, CancellationToken cancellationToken = default); + /// A that completes when the request is finished. /// Thrown when the request returns a non-success status code. [Post("/api/admin/superuser/{username}")] diff --git a/Flawless.Client/ViewModels/SettingViewModel.cs b/Flawless.Client/ViewModels/SettingViewModel.cs index cd83c2c..706659f 100644 --- a/Flawless.Client/ViewModels/SettingViewModel.cs +++ b/Flawless.Client/ViewModels/SettingViewModel.cs @@ -2,18 +2,14 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; -using System.Net; -using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; -using Avalonia.Threading; using DynamicData; using Flawless.Client.Models; using Flawless.Client.Remote; using Flawless.Client.Service; using Flawless.Client.ViewModels.ModalBox; using Flawless.Client.Views.ModalBox; -using LiveChartsCore; using ReactiveUI; using ReactiveUI.SourceGenerators; using Refit; @@ -49,9 +45,9 @@ public partial class SettingViewModel : RoutableViewModelBase [Reactive] private string _bio; - [Reactive] private DateTime? - _logSearchFrom = null, - _logSearchTo = null; + [Reactive] private DateTime + _logSearchFrom = DateTime.Now.AddDays(-1), + _logSearchTo = DateTime.Now; [Reactive] private int _page = 1; @@ -72,10 +68,10 @@ public partial class SettingViewModel : RoutableViewModelBase { using (UIHelper.MakeLoading("Fetch server data...")) { - await RefreshUsersCommand.Execute(); + await RefreshUsersAsync(); var sb = new StringBuilder(); - ServerBlacklist = sb.AppendJoin(",\n", await Api.C.Gateway.IpWhitelistGet()).ToString(); + ServerWhitelist = sb.AppendJoin(",\n", await Api.C.Gateway.IpWhitelistGet()).ToString(); ServerBlacklist = sb.Clear().AppendJoin(",\n", await Api.C.Gateway.IpBlacklistGet()).ToString(); } } @@ -244,7 +240,8 @@ public partial class SettingViewModel : RoutableViewModelBase Username = user.Username, Email = user.Email, IsActive = user.IsActive, - IsAdmin = user.IsAdmin ?? false + IsAdmin = user.IsAdmin ?? false, + CanEdit = user.Username != Api.C.Username.Value! }); } } @@ -257,9 +254,12 @@ public partial class SettingViewModel : RoutableViewModelBase [ReactiveCommand] private async Task CreateUserAsync() { - var result = new UserCreateDialogViewModel(); - result.Password = GenerateRandomPassword(); var opt = UIHelper.DefaultOverlayDialogOptionsYesNo(); + var result = new UserCreateDialogViewModel + { + Password = GenerateRandomPassword() + }; + while (true) { var r = await OverlayDialog.ShowModal(result, AppDefaultValues.HostId, opt); @@ -271,14 +271,14 @@ public partial class SettingViewModel : RoutableViewModelBase try { - await Api.C.Gateway.Register(new RegisterRequest + await Api.C.Gateway.AddUser(new RegisterRequest { Username = result.Username, Password = result.Password, Email = result.Email }); - - Users.Add(UserService.C.GetUserInfoAsync(result.Username)!); + + await this.RefreshUsersAsync(); UIHelper.NotifySuccess($"User {result.Username} create successfully"); } catch (ApiException ex) @@ -311,11 +311,12 @@ public partial class SettingViewModel : RoutableViewModelBase var newPassword = GenerateRandomPassword(); try { - await Api.C.Gateway.RenewPassword(new ResetPasswordRequest + await Api.C.Gateway.ResetPassword(new ResetPasswordRequest { Identity = username, NewPassword = newPassword }); + await UIHelper.SimpleAlert($"Password has been reset to {newPassword}"); } catch (Exception ex) @@ -386,7 +387,7 @@ public partial class SettingViewModel : RoutableViewModelBase { await Api.C.Gateway.SuperuserPost(username, active); Users.First(x => x.Username == username).IsAdmin = active; - UIHelper.NotifySuccess($"{username} has already {(active ? "enabled" : "disabled")}."); + UIHelper.NotifySuccess($"{username} has already set to {(active ? "superuser" : "nornmal user")}."); } catch (Exception ex) { diff --git a/Flawless.Client/Views/HomeView.axaml b/Flawless.Client/Views/HomeView.axaml index b524eef..7cd9bff 100644 --- a/Flawless.Client/Views/HomeView.axaml +++ b/Flawless.Client/Views/HomeView.axaml @@ -12,7 +12,7 @@ - + diff --git a/Flawless.Client/Views/ModalBox/IssueDetailEditView.axaml b/Flawless.Client/Views/ModalBox/IssueDetailEditView.axaml index 2a09a5b..f28cbb3 100644 --- a/Flawless.Client/Views/ModalBox/IssueDetailEditView.axaml +++ b/Flawless.Client/Views/ModalBox/IssueDetailEditView.axaml @@ -6,7 +6,7 @@ xmlns:vm="clr-namespace:Flawless.Client.ViewModels.ModalBox" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:DataType="vm:IssueEditDialogViewModel" - MinWidth="400" + MinWidth="500" x:Class="Flawless.Client.Views.ModalBox.IssueDetailEditView"> diff --git a/Flawless.Client/Views/ModalBox/UserCreateDialogView.axaml b/Flawless.Client/Views/ModalBox/UserCreateDialogView.axaml index 499ef1b..4d421ab 100644 --- a/Flawless.Client/Views/ModalBox/UserCreateDialogView.axaml +++ b/Flawless.Client/Views/ModalBox/UserCreateDialogView.axaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="using:Flawless.Client.ViewModels.ModalBox" x:Class="Flawless.Client.Views.ModalBox.UserCreateDialogView" + MinWidth="400" x:DataType="vm:UserCreateDialogViewModel"> diff --git a/Flawless.Client/Views/SettingView.axaml b/Flawless.Client/Views/SettingView.axaml index 9f59d30..1fc626e 100644 --- a/Flawless.Client/Views/SettingView.axaml +++ b/Flawless.Client/Views/SettingView.axaml @@ -39,19 +39,10 @@ - - - - - - - - - - - + + + - @@ -92,36 +83,28 @@ Command="{Binding CreateUserCommand}"/> - - - - - - - - - - - - - - + + + + + + + + +