From 0e7afa8efbafd1c426a2d2638f09036aa74d15be Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Thu, 2 Nov 2023 11:30:00 +0800 Subject: [PATCH] clear username & password after cancel registration --- .../Service/Hutao/HutaoUserOptions.cs | 9 ++++++++- .../Service/Hutao/HutaoUserService.cs | 2 +- .../View/Dialog/HutaoPassportLoginDialog.xaml | 6 +++++- .../Dialog/HutaoPassportRegisterDialog.xaml | 8 ++++++-- .../HutaoPassportResetPasswordDialog.xaml | 8 ++++++-- .../Dialog/HutaoPassportUnregisterDialog.xaml | 4 +++- .../ViewModel/Setting/HutaoPassportViewModel.cs | 17 +++-------------- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoUserOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoUserOptions.cs index 2dacefe0..f61058ff 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoUserOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Hutao/HutaoUserOptions.cs @@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using Microsoft.Extensions.Options; +using Snap.Hutao.Core.Setting; using Snap.Hutao.Web.Hutao; using System.Text.RegularExpressions; @@ -62,8 +63,11 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions public HutaoUserOptions Value { get => this; } - public async ValueTask PostLoginSucceedAsync(HomaPassportClient passportClient, ITaskContext taskContext, string username, string? token) + public async ValueTask PostLoginSucceedAsync(HomaPassportClient passportClient, ITaskContext taskContext, string username, string password, string? token) { + LocalSetting.Set(SettingKeys.PassportUserName, username); + LocalSetting.Set(SettingKeys.PassportPassword, password); + await taskContext.SwitchToMainThreadAsync(); UserName = username; this.token = token; @@ -84,6 +88,9 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions - + - + @@ -37,4 +41,4 @@ Style="{StaticResource CaptionTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordRequirementHint}"/> - + \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportResetPasswordDialog.xaml b/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportResetPasswordDialog.xaml index fb5895c9..78bb7a19 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportResetPasswordDialog.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportResetPasswordDialog.xaml @@ -13,7 +13,11 @@ mc:Ignorable="d"> - + @@ -37,4 +41,4 @@ Style="{StaticResource CaptionTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordRequirementHint}"/> - + \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportUnregisterDialog.xaml b/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportUnregisterDialog.xaml index 7e36d3d6..63e270ce 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportUnregisterDialog.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/HutaoPassportUnregisterDialog.xaml @@ -20,6 +20,8 @@ Severity="Error"/> @@ -40,4 +42,4 @@ Password="{x:Bind Password, Mode=TwoWay}" PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordHint}"/> - + \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/HutaoPassportViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/HutaoPassportViewModel.cs index f63a5a4e..f0709654 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/HutaoPassportViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/HutaoPassportViewModel.cs @@ -31,12 +31,6 @@ internal sealed partial class HutaoPassportViewModel : Abstraction.ViewModel await Launcher.LaunchUriAsync("https://homa.snapgenshin.com/redeem.html".ToUri()); } - private static void SaveUserNameAndPassword(string username, string password) - { - LocalSetting.Set(SettingKeys.PassportUserName, username); - LocalSetting.Set(SettingKeys.PassportPassword, password); - } - [Command("RegisterCommand")] private async Task RegisterAsync() { @@ -56,9 +50,8 @@ internal sealed partial class HutaoPassportViewModel : Abstraction.ViewModel if (response.IsOk()) { - SaveUserNameAndPassword(username, password); infoBarService.Information(response.Message); - await hutaoUserOptions.PostLoginSucceedAsync(homaPassportClient, taskContext, username, response.Data).ConfigureAwait(false); + await hutaoUserOptions.PostLoginSucceedAsync(homaPassportClient, taskContext, username, password, response.Data).ConfigureAwait(false); } } } @@ -109,10 +102,8 @@ internal sealed partial class HutaoPassportViewModel : Abstraction.ViewModel if (response.IsOk()) { - SaveUserNameAndPassword(username, password); infoBarService.Information(response.Message); - - await hutaoUserOptions.PostLoginSucceedAsync(homaPassportClient, taskContext, username, response.Data).ConfigureAwait(false); + await hutaoUserOptions.PostLoginSucceedAsync(homaPassportClient, taskContext, username, password, response.Data).ConfigureAwait(false); } } } @@ -144,10 +135,8 @@ internal sealed partial class HutaoPassportViewModel : Abstraction.ViewModel if (response.IsOk()) { - SaveUserNameAndPassword(username, password); infoBarService.Information(response.Message); - - await hutaoUserOptions.PostLoginSucceedAsync(homaPassportClient, taskContext, username, response.Data).ConfigureAwait(false); + await hutaoUserOptions.PostLoginSucceedAsync(homaPassportClient, taskContext, username, password, response.Data).ConfigureAwait(false); } } }