clear username & password after cancel registration

This commit is contained in:
Lightczx
2023-11-02 11:30:00 +08:00
parent b753728b7e
commit 0e7afa8efb
7 changed files with 32 additions and 22 deletions

View File

@@ -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<HutaoUserOpt
/// <inheritdoc/>
public HutaoUserOptions Value { get => this; }
public async ValueTask<bool> PostLoginSucceedAsync(HomaPassportClient passportClient, ITaskContext taskContext, string username, string? token)
public async ValueTask<bool> 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<HutaoUserOpt
public void LogoutOrUnregister()
{
LocalSetting.Set(SettingKeys.PassportUserName, string.Empty);
LocalSetting.Set(SettingKeys.PassportPassword, string.Empty);
UserName = null;
token = null;
IsLoggedIn = false;

View File

@@ -44,7 +44,7 @@ internal sealed partial class HutaoUserService : IHutaoUserService, IHutaoUserSe
if (response.IsOk())
{
if (await options.PostLoginSucceedAsync(passportClient, taskContext, userName, response.Data).ConfigureAwait(false))
if (await options.PostLoginSucceedAsync(passportClient, taskContext, userName, token: response.Data).ConfigureAwait(false))
{
isInitialized = true;
}

View File

@@ -13,7 +13,11 @@
mc:Ignorable="d">
<StackPanel Margin="0,8,0,0">
<TextBox PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}" Text="{x:Bind UserName, Mode=TwoWay}"/>
<TextBox
InputScope="EmailNameOrAddress"
IsSpellCheckEnabled="False"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}"
Text="{x:Bind UserName, Mode=TwoWay}"/>
<PasswordBox
Margin="0,16,0,0"
Password="{x:Bind Password, Mode=TwoWay}"

View File

@@ -13,7 +13,11 @@
mc:Ignorable="d">
<StackPanel Margin="0,8,0,0">
<TextBox PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}" Text="{x:Bind UserName, Mode=TwoWay}"/>
<TextBox
InputScope="EmailNameOrAddress"
IsSpellCheckEnabled="False"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}"
Text="{x:Bind UserName, Mode=TwoWay}"/>
<Grid Margin="0,16,0,0" ColumnSpacing="16">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
@@ -37,4 +41,4 @@
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordRequirementHint}"/>
</StackPanel>
</ContentDialog>
</ContentDialog>

View File

@@ -13,7 +13,11 @@
mc:Ignorable="d">
<StackPanel>
<TextBox PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}" Text="{x:Bind UserName, Mode=TwoWay}"/>
<TextBox
InputScope="EmailNameOrAddress"
IsSpellCheckEnabled="False"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}"
Text="{x:Bind UserName, Mode=TwoWay}"/>
<Grid Margin="0,16,0,0" ColumnSpacing="16">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
@@ -37,4 +41,4 @@
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordRequirementHint}"/>
</StackPanel>
</ContentDialog>
</ContentDialog>

View File

@@ -20,6 +20,8 @@
Severity="Error"/>
<TextBox
Margin="0,16,0,0"
InputScope="EmailNameOrAddress"
IsSpellCheckEnabled="False"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}"
Text="{x:Bind UserName, Mode=TwoWay}"/>
<Grid Margin="0,16,0,0" ColumnSpacing="16">
@@ -40,4 +42,4 @@
Password="{x:Bind Password, Mode=TwoWay}"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordHint}"/>
</StackPanel>
</ContentDialog>
</ContentDialog>

View File

@@ -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);
}
}
}