add verify for cancel registration

This commit is contained in:
Lightczx
2023-11-02 10:26:27 +08:00
parent 3ac0be4220
commit c6435f30eb
6 changed files with 64 additions and 11 deletions

View File

@@ -48,7 +48,7 @@ internal sealed partial class HutaoPassportRegisterDialog : ContentDialog
return;
}
HutaoResponse response = await homaPassportClient.VerifyAsync(UserName, false).ConfigureAwait(false);
HutaoResponse response = await homaPassportClient.RequestVerifyAsync(UserName, VerifyCodeRequestType.Registration).ConfigureAwait(false);
infoBarService.Information(response.GetLocalizationMessage());
}
}

View File

@@ -48,7 +48,7 @@ internal sealed partial class HutaoPassportResetPasswordDialog : ContentDialog
return;
}
HutaoResponse response = await homaPassportClient.VerifyAsync(UserName, false).ConfigureAwait(false);
HutaoResponse response = await homaPassportClient.RequestVerifyAsync(UserName, VerifyCodeRequestType.ResetPassword).ConfigureAwait(false);
infoBarService.Information(response.GetLocalizationMessage());
}
}

View File

@@ -22,8 +22,21 @@
Margin="0,16,0,0"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportUserNameHint}"
Text="{x:Bind UserName, Mode=TwoWay}"/>
<Grid Margin="0,16,0,0" ColumnSpacing="16">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBox PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportVerifyCodeHint}" Text="{x:Bind VerifyCode, Mode=TwoWay}"/>
<Button
Grid.Column="1"
VerticalAlignment="Stretch"
Command="{x:Bind VerifyCommand}"
Content="{shcm:ResourceString Name=ViewPageHutaoPassportVerifyCodeAction}"/>
</Grid>
<PasswordBox
Margin="0,16,0,0"
IsEnabled="{x:Bind VerifyCode, Converter={StaticResource StringBoolConverter}, Mode=OneWay}"
Password="{x:Bind Password, Mode=TwoWay}"
PlaceholderText="{shcm:ResourceString Name=ViewPageHutaoPassportPasswordHint}"/>
</StackPanel>

View File

@@ -1,14 +1,20 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.Common;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Web.Hutao;
namespace Snap.Hutao.View.Dialog;
[DependencyProperty("UserName", typeof(string))]
[DependencyProperty("Password", typeof(string))]
[DependencyProperty("VerifyCode", typeof(string))]
internal sealed partial class HutaoPassportUnregisterDialog : ContentDialog
{
private readonly HomaPassportClient homaPassportClient;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
public HutaoPassportUnregisterDialog(IServiceProvider serviceProvider)
@@ -16,6 +22,8 @@ internal sealed partial class HutaoPassportUnregisterDialog : ContentDialog
InitializeComponent();
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
homaPassportClient = serviceProvider.GetRequiredService<HomaPassportClient>();
infoBarService = serviceProvider.GetRequiredService<IInfoBarService>();
}
public async ValueTask<ValueResult<bool, (string UserName, string Passport)>> GetInputAsync()
@@ -25,4 +33,22 @@ internal sealed partial class HutaoPassportUnregisterDialog : ContentDialog
return new(result is ContentDialogResult.Primary, (UserName, Password));
}
[Command("VerifyCommand")]
private async Task VerifyAsync()
{
if (string.IsNullOrEmpty(UserName))
{
return;
}
if (!UserName.IsEmail())
{
infoBarService.Warning(SH.ViewModelHutaoPassportEmailNotValidHint);
return;
}
HutaoResponse response = await homaPassportClient.RequestVerifyAsync(UserName, VerifyCodeRequestType.CancelRegistration).ConfigureAwait(false);
infoBarService.Information(response.GetLocalizationMessage());
}
}

View File

@@ -40,21 +40,23 @@ internal sealed partial class HomaPassportClient
private readonly HutaoUserOptions hutaoUserOptions;
private readonly HttpClient httpClient;
/// <summary>
/// 异步获取验证码
/// </summary>
/// <param name="email">邮箱</param>
/// <param name="isResetPassword">是否重置账号密码</param>
/// <param name="token">取消令牌</param>
/// <returns>响应</returns>
public async ValueTask<HutaoResponse> VerifyAsync(string email, bool isResetPassword, CancellationToken token = default)
public async ValueTask<HutaoResponse> RequestVerifyAsync(string email, VerifyCodeRequestType requestType, CancellationToken token = default)
{
Dictionary<string, object> data = new()
{
["UserName"] = Encrypt(email),
["IsResetPassword"] = isResetPassword,
};
if (requestType.HasFlag(VerifyCodeRequestType.ResetPassword))
{
data["IsResetPassword"] = true;
}
if (requestType.HasFlag(VerifyCodeRequestType.CancelRegistration))
{
data["IsCancelRegistration"] = true;
}
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(HutaoEndpoints.PassportVerify)
.PostJson(data);

View File

@@ -0,0 +1,12 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hutao;
[Flags]
internal enum VerifyCodeRequestType
{
Registration = 0b0000,
ResetPassword = 0b0001,
CancelRegistration = 0b0010,
}