using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Newtonsoft.Json;
using RustTools.DataList;
using WinUIEx.Messaging;
namespace RustTools.Themes;
///
/// 找回密码
///
public sealed partial class RediscoverPassGrid : UserControl
{
public event RoutedEventHandler BackClick
{
add => BackButton.Click += value;
remove => BackButton.Click -= value;
}
public RediscoverPassGrid()
{
InitializeComponent();
accountBox.TextChanged += AccountBox_TextChanged;
codeBox.TextChanged += AccountBox_TextChanged;
passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
passwordyesBox.PasswordChanged += PasswordBox_PasswordChanged;
}
private void AccountBox_TextChanged(object sender, TextChangedEventArgs e)
{
redisButton.IsEnabled = IsEnabledButton;
}
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
redisButton.IsEnabled = IsEnabledButton;
}
///
/// 发送验证码
///
///
///
private async void ButtonIcon_Click(object sender, RoutedEventArgs e)
{
Toast.IsOpen = false;
if (accountBox.Text == string.Empty) {
Toast.IsOpen = true;
Toast.Title = "提示";
Toast.Subtitle = "账号不能为空";
return;
}
try
{
var v = await ApiFox.user.requestChangePassword(accountBox.Text);
var message = JsonConvert.DeserializeObject(v);
Toast.IsOpen = true;
Toast.Title = "提示";
Toast.Subtitle = message.message;
await Task.Delay(millisecondsDelay: 1000);
Toast.IsOpen = false;
}
catch (Exception ex) {
Toast.IsOpen = true;
Toast.Title = "提示";
Toast.Subtitle = ex.Message;
await Task.Delay(millisecondsDelay: 1000);
Toast.IsOpen = false;
}
}
public bool IsEnabledButton =>!string.IsNullOrEmpty(accountBox.Text)&&
!string.IsNullOrEmpty(passwordBox.Password) &&
!string.IsNullOrEmpty(passwordyesBox.Password) &&
!string.IsNullOrEmpty(codeBox.Text);
///
/// 找回密码
///
///
///
private async void Button_Click(object sender, RoutedEventArgs e)
{
Toast.IsOpen = false;
try
{
var v = await ApiFox.user.changePassword(accountBox.Text, passwordBox.Password, codeBox.Text);
var message = JsonConvert.DeserializeObject(v);
Toast.IsOpen = true;
Toast.Title = "提示";
Toast.Subtitle = message.message;
await Task.Delay(millisecondsDelay: 1000);
Toast.IsOpen = false;
}
catch (Exception ex)
{
Toast.IsOpen = true;
Toast.Title = "提示";
Toast.Subtitle = ex.Message;
await Task.Delay(millisecondsDelay: 1000);
Toast.IsOpen = false;
}
}
private void RediscoverPassGrid_BackClick(object sender, RoutedEventArgs e) => throw new NotImplementedException();
}