From 47c06f2b9acc13a50320a30cf60ebee7e641c4be Mon Sep 17 00:00:00 2001 From: rmbgame Date: Sun, 23 May 2021 13:28:30 +0800 Subject: [PATCH] save --- .../Application/UI/Styles/DrawingSvg.xaml | 4 + .../LocalAuthPage/AddAuthWindow.axaml.cs | 11 ++- .../LocalAuthPage/PasswordWindow.axaml.cs | 9 +- .../Views/Windows/MessageBoxWindow.axaml.cs | 8 +- .../Services/Mvvm/AuthService.cs | 99 ++++++++++++++----- .../UI/Resx/AppResources.Designer.cs | 18 ++++ .../UI/Resx/AppResources.resx | 8 +- .../Pages/LocalAuthPageViewModel.cs | 31 ++++-- .../LocalAuthPage/AddAuthWindowViewModel.cs | 56 +++++++++-- .../LocalAuthPage/AuthTradeWindowViewModel.cs | 32 +++++- .../EncryptionAuthWindowViewModel.cs | 16 +-- .../ExportAuthWindowViewModel.cs | 14 ++- 12 files changed, 249 insertions(+), 57 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Styles/DrawingSvg.xaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Styles/DrawingSvg.xaml index cea1d729d..dfc922754 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Styles/DrawingSvg.xaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Styles/DrawingSvg.xaml @@ -23,6 +23,10 @@ + + M8.35464 2.14678C8.15946 1.95123 7.84268 1.95105 7.64728 2.14638C6.40416 3.38902 5.02923 4 3.5 4C3.22386 4 3 4.22386 3 4.5V7.50126C3 10.4242 4.35378 12.4971 7 13.6523V10C7 9.06808 7.63739 8.28503 8.5 8.06301V8C8.5 6.34315 9.84315 5 11.5 5C12.0464 5 12.5587 5.14609 13 5.40135V4.5C13 4.22386 12.7761 4 12.5 4C10.9689 4 9.5947 3.38913 8.35464 2.14678ZM9.5 9V8C9.5 6.89543 10.3954 6 11.5 6C12.6046 6 13.5 6.89543 13.5 8V9H14C14.5523 9 15 9.44772 15 10V14C15 14.5523 14.5523 15 14 15H9C8.44771 15 8 14.5523 8 14V10C8 9.44772 8.44772 9 9 9H9.5ZM10.5 8V9H12.5V8C12.5 7.44772 12.0523 7 11.5 7C10.9477 7 10.5 7.44772 10.5 8ZM12.25 12C12.25 11.5858 11.9142 11.25 11.5 11.25C11.0858 11.25 10.75 11.5858 10.75 12C10.75 12.4142 11.0858 12.75 11.5 12.75C11.9142 12.75 12.25 12.4142 12.25 12Z + + M8.75 13C9.99264 13 11 14.0074 11 15.25V18.75C11 19.9926 9.99264 21 8.75 21H5.25C4.00736 21 3 19.9926 3 18.75V15.25C3 14.0074 4.00736 13 5.25 13H8.75ZM18.75 13C19.9926 13 21 14.0074 21 15.25V18.75C21 19.9926 19.9926 21 18.75 21H15.25C14.0074 21 13 19.9926 13 18.75V15.25C13 14.0074 14.0074 13 15.25 13H18.75ZM8.75 3C9.99264 3 11 4.00736 11 5.25V8.75C11 9.99264 9.99264 11 8.75 11H5.25C4.00736 11 3 9.99264 3 8.75V5.25C3 4.00736 4.00736 3 5.25 3H8.75ZM18.75 3C19.9926 3 21 4.00736 21 5.25V8.75C21 9.99264 19.9926 11 18.75 11H15.25C14.0074 11 13 9.99264 13 8.75V5.25C13 4.00736 14.0074 3 15.25 3H18.75Z diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml.cs index 168adddc0..d6d490001 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml.cs @@ -3,6 +3,7 @@ using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using System.Application.Services; +using System.Application.UI.ViewModels; using System.Collections.Generic; using System.Properties; @@ -10,9 +11,11 @@ namespace System.Application.UI.Views.Windows { public class AddAuthWindow : FluentWindow { + private AddAuthWindowViewModel? vm; public AddAuthWindow() : base() { InitializeComponent(); + vm = this.DataContext as AddAuthWindowViewModel; #if DEBUG this.AttachDevTools(); #endif @@ -50,7 +53,7 @@ namespace System.Application.UI.Views.Windows { if (s != null && s.Result.Length > 0) { - AuthService.Current.ImportAuthenticatorFile(s.Result[0]); + vm.ImportSteamPlusPlusV2(s.Result[0]); } }); } @@ -70,7 +73,7 @@ namespace System.Application.UI.Views.Windows { if (s != null && s.Result.Length > 0) { - AuthService.Current.LoadSteamToolsV1Authenticator(s.Result[0]); + vm.ImportSteamPlusPlusV1(s.Result[0]); } }); } @@ -91,7 +94,7 @@ namespace System.Application.UI.Views.Windows { if (s != null && s.Result.Length > 0) { - AuthService.Current.ImportSDAFile(s.Result[0]); + vm.ImportSDA(s.Result[0]); } }); } @@ -111,7 +114,7 @@ namespace System.Application.UI.Views.Windows { if (s != null && s.Result.Length > 0) { - AuthService.Current.ImportWinAuthenticators(s.Result[0]); + vm.ImportWinAuth(s.Result[0]); } }); diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs index 1bd8a12d8..ca41780c8 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs @@ -1,10 +1,11 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Primitives; using Avalonia.Markup.Xaml; namespace System.Application.UI.Views.Windows { - public class PasswordWindow : FluentWindow + public class PasswordWindow : Window { public PasswordWindow() : base() { @@ -18,5 +19,11 @@ namespace System.Application.UI.Views.Windows { AvaloniaXamlLoader.Load(this); } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome; + } } } diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/MessageBoxWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/MessageBoxWindow.axaml.cs index 444478a09..b7311fd3f 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/MessageBoxWindow.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/MessageBoxWindow.axaml.cs @@ -1,5 +1,6 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Primitives; using Avalonia.Markup.Xaml; using Avalonia.Styling; using System.Reflection; @@ -19,7 +20,6 @@ namespace System.Application.UI.Views.Windows //} InitializeComponent(); - this.ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome; #if DEBUG this.AttachDevTools(); #endif @@ -29,5 +29,11 @@ namespace System.Application.UI.Views.Windows { AvaloniaXamlLoader.Load(this); } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome; + } } } \ No newline at end of file diff --git a/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs b/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs index 41b323a95..24a417a11 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs @@ -73,13 +73,31 @@ namespace System.Application.Services } } - public async Task HasPasswordEncryptionShowPassWordWindow() + /// + /// 是否设置了密码加密 + /// + /// + public async Task HasPasswordEncryption() { var auths = await repository.GetAllSourceAsync(); if (!auths.Any_Nullable()) { return false; } + return repository.HasSecondaryPassword(auths); + } + + /// + /// 是否设置了密码加密且弹出解密框 + /// + /// + public async Task<(bool success, string? password)> HasPasswordEncryptionShowPassWordWindow() + { + var auths = await repository.GetAllSourceAsync(); + if (!auths.Any_Nullable()) + { + return (false, null); + } var hasPassword = repository.HasSecondaryPassword(auths); if (hasPassword) { @@ -87,15 +105,15 @@ namespace System.Application.Services var list = await repository.ConvertToList(auths, password); if (list.Any_Nullable()) { - return true; + return (true, password); } Toast.Show(AppResources.LocalAuth_ProtectionAuth_PasswordError); - return false; + return (false, null); } else { - //没有密码直接成功 - return true; + //没有设置密码直接成功 + return (true, null); } } @@ -108,7 +126,7 @@ namespace System.Application.Services /// /// WinAuth令牌导入 /// - public void ImportWinAuthenticators(string file) + public void ImportWinAuthenticators(string file, bool isLocal, string? password) { StringBuilder lines = new StringBuilder(); bool retry; @@ -124,7 +142,7 @@ namespace System.Application.Services try { using var sr = new StringReader(lines.ToString()); - string line; + string? line; while ((line = sr.ReadLine()) != null) { linenumber++; @@ -282,7 +300,7 @@ namespace System.Application.Services ToastService.Current.Notify(AppResources.LocalAuth_AddAuthSyncTip); importedAuthenticator.Value.Sync(); - AuthService.AddOrUpdateSaveAuthenticators(importedAuthenticator); + AuthService.AddOrUpdateSaveAuthenticators(importedAuthenticator, isLocal, password); } ToastService.Current.Notify(AppResources.LocalAuth_AddAuthSuccess); } @@ -300,7 +318,7 @@ namespace System.Application.Services /// Steam APP令牌导入 /// /// true if successful - public bool ImportSteamGuard(string name, string uuid, string steamGuard) + public bool ImportSteamGuard(string name, string uuid, string steamGuard, bool isLocal, string? password) { if (string.IsNullOrEmpty(uuid)) { @@ -389,11 +407,11 @@ namespace System.Application.Services { Name = name, Value = auth, - }); + }, isLocal, password); return true; } - public bool ImportSDAFile(string mafile) + public bool ImportSDAFile(string mafile, bool isLocal, string? password) { string data; if (File.Exists(mafile) == false || (data = File.ReadAllText(mafile)) == null) @@ -453,37 +471,48 @@ namespace System.Application.Services auth.SteamData = token.ToString(Newtonsoft.Json.Formatting.None); winAuth.Value = auth; - AddOrUpdateSaveAuthenticators(winAuth); + AddOrUpdateSaveAuthenticators(winAuth,isLocal,password); return true; } /// /// 导入Steam++导出的令牌数据文件 V2 /// - public async void ImportAuthenticatorFile(string file, string? password = null) + public async void ImportAuthenticatorFile(string file, bool isLocal, string? password, string? exportPassword = null) { if (File.Exists(file)) { var bt = await File.ReadAllBytesAsync(file); - var result = await repository.ImportAsync(null, bt); + Run: + var result = await repository.ImportAsync(password, bt); if (result.resultCode == IGameAccountPlatformAuthenticatorRepository.ImportResultCode.Success) { foreach (var item in result.result) { - await repository.InsertOrUpdateAsync(item, true); + AddOrUpdateSaveAuthenticators(new MyAuthenticator(item), isLocal, password); } + ToastService.Current.Notify(AppResources.LocalAuth_AddAuthSuccess); } else if (result.resultCode == IGameAccountPlatformAuthenticatorRepository.ImportResultCode.PartSuccess) { foreach (var item in result.result) { - await repository.InsertOrUpdateAsync(item, true); + AddOrUpdateSaveAuthenticators(new MyAuthenticator(item), isLocal, password); } Toast.Show(AppResources.LocalAuth_AddAuth_PartSuccess); } + else if (result.resultCode == IGameAccountPlatformAuthenticatorRepository.ImportResultCode.IncorrectPwdOrIsNotLocal) + { + Toast.Show(AppResources.LocalAuth_ProtectionAuth_PasswordErrorTip); + password = await PasswordWindowViewModel.ShowPasswordDialog(); + if (string.IsNullOrWhiteSpace(password)) + { + goto Run; + } + } else { Toast.Show(string.Format(AppResources.LocalAuth_ExportAuth_Error, result.resultCode)); @@ -491,7 +520,7 @@ namespace System.Application.Services }; } - public void LoadSteamToolsV1Authenticator(string file) + public void ImportSteamToolsV1Authenticator(string file, bool isLocal, string? password) { var authString = File.ReadAllText(file).DecompressString(); if (!string.IsNullOrEmpty(authString)) @@ -515,7 +544,7 @@ namespace System.Application.Services { var wa = new MyAuthenticator(); wa.ReadXml(reader, null); - AddOrUpdateSaveAuthenticators(wa); + AddOrUpdateSaveAuthenticators(wa, isLocal, password); } } else @@ -527,15 +556,15 @@ namespace System.Application.Services } } - public static void AddOrUpdateSaveAuthenticators(GAPAuthenticatorDTO auth) + public static void AddOrUpdateSaveAuthenticators(GAPAuthenticatorDTO auth, bool isLocal, string? password) { - AddOrUpdateSaveAuthenticators(new MyAuthenticator(auth)); + AddOrUpdateSaveAuthenticators(new MyAuthenticator(auth), isLocal, password); } - public static async void AddOrUpdateSaveAuthenticators(MyAuthenticator auth) + public static async void AddOrUpdateSaveAuthenticators(MyAuthenticator auth, bool isLocal, string? password) { var repository = DI.Get(); - await repository.InsertOrUpdateAsync(auth.AuthenticatorData, false); + await repository.InsertOrUpdateAsync(auth.AuthenticatorData, isLocal, password); if (Current.Authenticators.Items.Any(s => s.Id == auth.Id)) { return; @@ -543,6 +572,32 @@ namespace System.Application.Services Current.Authenticators.AddOrUpdate(auth); } + public static async void AddOrUpdateSaveAuthenticators(IEnumerable auths) + { + if (auths.Any_Nullable()) + { + var repository = DI.Get(); + var sources = await repository.GetAllSourceAsync(); + if (!sources.Any_Nullable()) + { + foreach (var item in auths) + { + AddOrUpdateSaveAuthenticators(item, false, null); + } + } + else + { + var hasLocal = repository.HasLocal(sources); + var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); + var password = result.password; + foreach (var item in auths) + { + AddOrUpdateSaveAuthenticators(item, hasLocal, password); + } + } + } + } + public static async void DeleteSaveAuthenticators(MyAuthenticator auth) { var repository = DI.Get(); diff --git a/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs b/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs index bc67015d2..0dca18357 100644 --- a/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs +++ b/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs @@ -1818,6 +1818,15 @@ namespace System.Application.UI.Resx { } } + /// + /// 查找类似 没有设置密码无法锁定令牌 的本地化字符串。 + /// + public static string LocalAuth_LockError { + get { + return ResourceManager.GetString("LocalAuth_LockError", resourceCulture); + } + } + /// /// 查找类似 编辑令牌 的本地化字符串。 /// @@ -2223,6 +2232,15 @@ namespace System.Application.UI.Resx { } } + /// + /// 查找类似 锁定 的本地化字符串。 + /// + public static string Lock { + get { + return ResourceManager.GetString("Lock", resourceCulture); + } + } + /// /// 查找类似 登 录 的本地化字符串。 /// diff --git a/src/ST.Client.Desktop/UI/Resx/AppResources.resx b/src/ST.Client.Desktop/UI/Resx/AppResources.resx index 829e56b02..1ee24be9a 100644 --- a/src/ST.Client.Desktop/UI/Resx/AppResources.resx +++ b/src/ST.Client.Desktop/UI/Resx/AppResources.resx @@ -708,6 +708,9 @@ 导入失败,请检查数据是否正确。 + + 没有设置密码无法锁定令牌 + 编辑令牌 @@ -843,6 +846,9 @@ WinAuth是Windows的便携式开放源代码身份验证器,它提供基于计数器或基于时间的RFC 6238身份验证器和常见的实现。导入方法:从WinAuth导出txt文件之后在此选择从WinAuth导出的txt文件进行导入。 + + 锁定 + 登 录 @@ -1313,4 +1319,4 @@ 起始页 - + \ No newline at end of file diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs index 41b6b8c75..213330bf6 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs @@ -24,8 +24,20 @@ namespace System.Application.UI.ViewModels AddAuthCommand = ReactiveCommand.Create(AddAuthMenu_Click); RefreshAuthCommand = ReactiveCommand.Create(() => AuthService.Current.Initialize(true)); EncryptionAuthCommand = ReactiveCommand.Create(ShowEncryptionAuthWindow); - ExportAuthCommand = ReactiveCommand.Create(ShowExportAuthAuthWindow); + LockCommand = ReactiveCommand.Create(async () => + { + var result = await AuthService.Current.HasPasswordEncryption(); + if (result) + { + AuthService.Current.Authenticators.Clear(); + Activation(); + } + else + { + Toast.Show(AppResources.LocalAuth_LockError); + } + }); MenuItems = new ObservableCollection() { @@ -34,15 +46,17 @@ namespace System.Application.UI.ViewModels // Items = new[] // { new MenuItemViewModel(nameof(AppResources.Add)) { IconKey="AddDrawing", - Command= AddAuthCommand }, - new MenuItemViewModel(nameof(AppResources.Encrypt)) {IconKey="LockDrawing", - Command =EncryptionAuthCommand }, + Command = AddAuthCommand }, + new MenuItemViewModel(nameof(AppResources.Encrypt)) {IconKey="ShieldLockDrawing", + Command = EncryptionAuthCommand }, //new MenuItemViewModel(nameof(AppResources.Edit)) { IconKey="EditDrawing" }, new MenuItemViewModel(nameof(AppResources.Export)) { IconKey="ExportDrawing", - Command= ExportAuthCommand }, + Command = ExportAuthCommand }, new MenuItemViewModel(), + new MenuItemViewModel(nameof(AppResources.Lock)) {IconKey="LockDrawing", + Command = LockCommand }, new MenuItemViewModel(nameof(AppResources.Refresh)) {IconKey="RefreshDrawing", - Command= RefreshAuthCommand }, + Command = RefreshAuthCommand }, //new MenuItemViewModel(), //new MenuItemViewModel(nameof(AppResources.Encrypt)) {IconKey="LockDrawing" }, //new MenuItemViewModel(nameof(AppResources.CloudSync)) {IconKey="CloudDrawing" }, @@ -75,6 +89,8 @@ namespace System.Application.UI.ViewModels public ReactiveCommand EncryptionAuthCommand { get; } + public ReactiveCommand LockCommand { get; } + public ReactiveCommand RefreshAuthCommand { get; } public ReactiveCommand ExportAuthCommand { get; } @@ -137,7 +153,8 @@ namespace System.Application.UI.ViewModels public async void ShowSteamAuthData(MyAuthenticator auth) { - if (await AuthService.Current.HasPasswordEncryptionShowPassWordWindow()) + var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); + if (result.success) { if (auth.AuthenticatorData.Value is GAPAuthenticatorValueDTO.SteamAuthenticator) { diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AddAuthWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AddAuthWindowViewModel.cs index 7866a87a6..642914452 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AddAuthWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AddAuthWindowViewModel.cs @@ -1,5 +1,6 @@ using ReactiveUI; using System.Application.Models; +using System.Application.Repositories; using System.Application.Services; using System.Application.UI.Resx; using System.IO; @@ -13,20 +14,40 @@ namespace System.Application.UI.ViewModels public class AddAuthWindowViewModel : WindowViewModel { readonly IHttpService httpService = DI.Get(); + readonly IGameAccountPlatformAuthenticatorRepository repository = DI.Get(); public AddAuthWindowViewModel() : base() { Title = ThisAssembly.AssemblyTrademark + " | " + AppResources.LocalAuth_AddAuth; + Initialize(); } - private GAPAuthenticatorValueDTO.SteamAuthenticator _SteamAuthenticator; + private GAPAuthenticatorValueDTO.SteamAuthenticator? _SteamAuthenticator; private GAPAuthenticatorValueDTO.SteamAuthenticator.EnrollState _Enroll = new() { RequiresLogin = true }; + private string? AuthPassword; + private bool AuthIsLocal; - public string AuthName { get; set; } + private async void Initialize() + { + var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); + if (result.success) + { + AuthPassword = result.password; + } + else + { + AuthPassword = null; + } + var auths = await repository.GetAllSourceAsync(); + AuthIsLocal = repository.HasLocal(auths); + } - public string UUID { get; set; } - public string SteamGuard { get; set; } + public string? AuthName { get; set; } + + public string? UUID { get; set; } + + public string? SteamGuard { get; set; } public bool RequiresLogin { @@ -53,7 +74,7 @@ namespace System.Application.UI.ViewModels } } - public string UserName + public string? UserName { get { @@ -65,7 +86,7 @@ namespace System.Application.UI.ViewModels } } - public string Password + public string? Password { get { @@ -149,7 +170,7 @@ namespace System.Application.UI.ViewModels public void ImportSteamGuard() { - if (AuthService.Current.ImportSteamGuard(AuthName, UUID, SteamGuard)) + if (AuthService.Current.ImportSteamGuard(AuthName, UUID, SteamGuard, AuthIsLocal, AuthPassword)) { ToastService.Current.Notify(AppResources.LocalAuth_AddAuthSuccess); } @@ -225,7 +246,7 @@ namespace System.Application.UI.ViewModels { Name = nameof(GamePlatform.Steam) + "(" + UserName + ")", Value = _SteamAuthenticator - }); + }, AuthIsLocal, AuthPassword); RequiresActivation = true; RevocationCode = _Enroll.RevocationCode; @@ -261,5 +282,24 @@ namespace System.Application.UI.ViewModels } + public void ImportWinAuth(string file) + { + AuthService.Current.ImportWinAuthenticators(file,AuthIsLocal,AuthPassword); + } + + public void ImportSDA(string file) + { + AuthService.Current.ImportSDAFile(file, AuthIsLocal, AuthPassword); + } + + public void ImportSteamPlusPlusV1(string file) + { + AuthService.Current.ImportSteamToolsV1Authenticator(file, AuthIsLocal, AuthPassword); + } + + public void ImportSteamPlusPlusV2(string file) + { + AuthService.Current.ImportAuthenticatorFile(file, AuthIsLocal, AuthPassword); + } } } \ No newline at end of file diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AuthTradeWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AuthTradeWindowViewModel.cs index 2df3b845f..461d1ada7 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AuthTradeWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/AuthTradeWindowViewModel.cs @@ -2,6 +2,7 @@ using DynamicData; using DynamicData.Binding; using ReactiveUI; using System.Application.Models; +using System.Application.Repositories; using System.Application.Services; using System.Application.UI.Resx; using System.Collections.Generic; @@ -36,6 +37,8 @@ namespace System.Application.UI.ViewModels this.RaisePropertyChanged(nameof(IsConfirmationsEmpty)); this.RaisePropertyChanged(nameof(ConfirmationsConutMessage)); }); + + Initialize(); } public AuthTradeWindowViewModel(MyAuthenticator auth) : this() @@ -55,6 +58,25 @@ namespace System.Application.UI.ViewModels Refresh_Click(); } + private string? AuthPassword; + private bool AuthIsLocal; + + private async void Initialize() + { + var repository = DI.Get(); + var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); + if (result.success) + { + AuthPassword = result.password; + } + else + { + AuthPassword = null; + } + var auths = await repository.GetAllSourceAsync(); + AuthIsLocal = repository.HasLocal(auths); + } + #region LoginData private string? _UserName; public string? UserName @@ -239,7 +261,7 @@ namespace System.Application.UI.ViewModels { IsLoggedIn = false; _Authenticator.SessionData = null; - AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator); + AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator,AuthIsLocal,AuthPassword); } } @@ -291,7 +313,7 @@ namespace System.Application.UI.ViewModels ToastService.Current.Notify(AppResources.User_LoiginSuccess); IsLoggedIn = true; _Authenticator.SessionData = RememberMe ? steam.Session.ToString() : null; - AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator); + AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator, AuthIsLocal, AuthPassword); } try { @@ -311,7 +333,7 @@ namespace System.Application.UI.ViewModels // 获取新交易后保存 if (!string.IsNullOrEmpty(_Authenticator.SessionData)) { - AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator); + AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator, AuthIsLocal, AuthPassword); } IsLoading = false; } @@ -563,7 +585,7 @@ namespace System.Application.UI.ViewModels CancelComfirmAll = null; RefreshConfirmationsList(); ToastService.Current.Notify(AppResources.LocalAuth_AuthTrade_ConfirmSuccess); - AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator); + AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator, AuthIsLocal, AuthPassword); } } @@ -617,7 +639,7 @@ namespace System.Application.UI.ViewModels CancelCancelAll = null; RefreshConfirmationsList(); ToastService.Current.Notify(AppResources.LocalAuth_AuthTrade_ConfirmCancel); - AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator); + AuthService.AddOrUpdateSaveAuthenticators(MyAuthenticator, AuthIsLocal, AuthPassword); } } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/EncryptionAuthWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/EncryptionAuthWindowViewModel.cs index 6090bbc1f..c1978f8ec 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/EncryptionAuthWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/EncryptionAuthWindowViewModel.cs @@ -18,15 +18,21 @@ namespace System.Application.UI.ViewModels Initialize(); } - public async void Initialize() + private async void Initialize() { + var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); + if (!result.success) + { + this.Close(); + } + var auths = await repository.GetAllSourceAsync(); IsPasswordEncrypt = repository.HasSecondaryPassword(auths); IsOnlyCurrentComputerEncrypt = repository.HasLocal(auths); if (IsPasswordEncrypt) { - //Password = "******"; - //VerifyPassword = "******"; + Password = result.password; + VerifyPassword = result.password; } } @@ -60,10 +66,6 @@ namespace System.Application.UI.ViewModels public async void EncryptionAuth() { - if (!await AuthService.Current.HasPasswordEncryptionShowPassWordWindow()) - { - return; - } var auths = await repository.GetAllSourceAsync(); var hasPassword = repository.HasSecondaryPassword(auths); var hasLocal = repository.HasLocal(auths); diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/ExportAuthWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/ExportAuthWindowViewModel.cs index 62e762e8c..9f20b714c 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/ExportAuthWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/ExportAuthWindowViewModel.cs @@ -51,8 +51,20 @@ namespace System.Application.UI.ViewModels } - public void ExportAuth() + public async void ExportAuth() { + var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); + if (!result.success) + { + this.Close(); + } + + if (string.IsNullOrEmpty(Path)) + { + Toast.Show(AppResources.LocalAuth_ProtectionAuth_PathError); + return; + } + if (IsPasswordEncrypt) { if (string.IsNullOrWhiteSpace(VerifyPassword) && VerifyPassword != Password)