修复BUG,添加找回密码

This commit is contained in:
muqing 2024-08-17 14:41:34 +08:00
parent b9b309b123
commit 41d4624315
16 changed files with 451 additions and 137 deletions

View File

@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using RustTools.muqing;
using RustTools.Views;
using static IniHelper;
namespace RustTools.ApiFox;
@ -70,6 +71,12 @@ public class user
return task;
}
/// <summary>
/// 激活用户
/// </summary>
/// <param name="account"></param>
/// <param name="key"></param>
/// <returns></returns>
public static async Task<string> enableAccount(string account, string key)
{
var task = await wl.postAsync("/php/user.php?action=enableAccount", new string[][]
@ -80,4 +87,43 @@ public class user
return task;
}
/// <summary>
/// 修改密码 发送邮箱验证码
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
public static async Task<string> requestChangePassword(string account)
{
var pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
var v = Regex.IsMatch(account, pattern);
var task = await wl.postAsync("/php/user.php?action=requestChangePassword", new string[][]
{
new []{ "account",account},
new []{ "isEmail", v.ToString().ToLower()}
});
return task;
}
/// <summary>
/// 修改密码
/// </summary>
/// <param name="account"></param>
/// <param name="newPassword"></param>
/// <param name="code"></param>
/// <returns></returns>
public static async Task<string> changePassword(string account, string newPassword, string code)
{
var pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
var v = Regex.IsMatch(account, pattern);
var task = await wl.postAsync("/php/user.php?action=changePassword", new string[][]
{
new []{ "account",account},
new []{ "isEmail", v.ToString().ToLower()},
new []{ "code", code},
new []{ "newPassword", newPassword}
});
return task;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 148 KiB

View File

@ -14,11 +14,11 @@ public sealed partial class MainWindow : WindowEx
{
InitializeComponent();
gj.SetBackTheme(this);
AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
//AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/Icon.ico"));
Content = null;
ExtendsContentIntoTitleBar = true;
this.SetIcon("Assets/WindowIcon.ico");
//AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
Title = "AppDisplayName".GetLocalized();
// Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239
dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
settings.ColorValuesChanged += Settings_ColorValuesChanged;

View File

@ -29,8 +29,22 @@
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Never</AppxBundle>
<AppxPackageDir>D:\RustTools</AppxPackageDir>
</PropertyGroup>
<ItemGroup>
<None Remove="RustTools_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="RustTools_TemporaryKey.pfx" />
</ItemGroup>
<!--<Target Name="RemoveFoldersWithMuiFiles" AfterTargets="Build">
<ItemGroup>
<RemovingFiles Include="$(OutDir)*\*.mui" Exclude="$(OutDir)en-us\*.mui" />
<RemovingFolders Include="@(RemovingFiles->'%(RootDir)%(Directory)')" />
</ItemGroup>
<RemoveDir Directories="@(RemovingFolders)" />
</Target>-->
<ItemGroup>
@ -51,6 +65,8 @@
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<!--在vs code 中必须加上不然没有任何图标-->
<ItemGroup>
<Content Include="Assets\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="RustTools.Themes.LoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@ -16,6 +17,10 @@
Background="{StaticResource CardStrokeColorDefault}"
CornerRadius="13">
<Grid MinWidth="290" HorizontalAlignment="Center">
<local:RediscoverPassGrid
x:Name="RediscoverPassGrid_view"
BackClick="Back_Click"
Visibility="Collapsed" />
<StackPanel x:Name="login_view">
<TextBlock HorizontalAlignment="Center" Text="登陆" />
<StackPanel>
@ -30,6 +35,11 @@
PlaceholderText="密码" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button
Margin="0,0,36,0"
HorizontalAlignment="Right"
Click="Back_Click"
Content="找回密码" />
<Button
Name="loginButton"
Width="100"
@ -40,7 +50,7 @@
Style="{StaticResource AccentButtonStyle}" />
<Button
Margin="0,0,0,0"
Click="enroll_Click"
Click="Back_Click"
Content="注册" />
</StackPanel>
<CheckBox x:Name="agreementCheck">

View File

@ -26,11 +26,11 @@ public sealed partial class LoginPage : UserControl
ZpasswordBox.PasswordChanged += ZPasswordBox_PasswordChanged;
ZpasswordyesBox.PasswordChanged += ZPasswordBox_PasswordChanged;
ZaccountBox.Text = "muqing1";
ZnameBox.Text = "muqing153";
ZpasswordBox.Password = "123456";
ZpasswordBox.Password= "123456";
ZemialBox.Text="123456@qq.com";
//ZaccountBox.Text = "muqing1";
//ZnameBox.Text = "muqing153";
//ZpasswordBox.Password = "123456";
//ZpasswordBox.Password= "123456";
//ZemialBox.Text="123456@qq.com";
}
@ -41,18 +41,26 @@ public sealed partial class LoginPage : UserControl
/// <param name="e"></param>
private void Back_Click(object sender, RoutedEventArgs e)
{
var storyboard = CreateFadeTransitionStoryboard(enroll_view,login_view);
storyboard.Begin();
}
/// <summary>
/// Çл»µ½×¢²á
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void enroll_Click(object sender, RoutedEventArgs e)
var frameworkElement = sender as Button;
if (frameworkElement == null)
{
var storyboard = CreateFadeTransitionStoryboard(login_view, enroll_view);
storyboard.Begin();
return;
}
gj.sc(frameworkElement);
if (frameworkElement.Content.ToString()=="×¢²á")
{
CreateFadeTransitionStoryboard(login_view,enroll_view).Begin();
}else if (frameworkElement.Content.ToString() == "ÕÒ»ØÃÜÂë")
{
CreateFadeTransitionStoryboard(login_view, RediscoverPassGrid_view).Begin();
}
else if(enroll_view.Visibility==Visibility.Visible)
{
CreateFadeTransitionStoryboard(enroll_view, login_view).Begin();
}else if (RediscoverPassGrid_view.Visibility == Visibility.Visible)
{
CreateFadeTransitionStoryboard(RediscoverPassGrid_view, login_view).Begin();
}
}
private Storyboard CreateFadeTransitionStoryboard(FrameworkElement fromElement, FrameworkElement toElement)

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="RustTools.Themes.RediscoverPassGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:RustTools.Themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<StackPanel>
<local:ButtonIcon x:Name="BackButton" Glyph="&#xE72B;" />
<TextBlock HorizontalAlignment="Center" Text="找回密码" />
<StackPanel>
<TextBox
Name="accountBox"
Margin="0,16,0,16"
InputScope="AlphanumericPin"
PlaceholderText="账号" />
<PasswordBox
Name="passwordBox"
Margin="0,0,0,16"
PlaceholderText="密码" />
<PasswordBox
Name="passwordyesBox"
Margin="0,0,0,16"
PlaceholderText="确认密码" />
<StackPanel Orientation="Horizontal">
<TextBox
Name="codeBox"
MinWidth="260"
Margin="0,0,0,16"
VerticalAlignment="Center"
MaxLength="6"
PlaceholderText="邮箱验证码" />
<local:ButtonIcon
Margin="6,0,0,16"
VerticalAlignment="Center"
Click="ButtonIcon_Click"
Glyph="&#xE724;"
ToolTipService.ToolTip="发送" />
</StackPanel>
</StackPanel>
<Button
x:Name="redisButton"
Margin="0,0,0,0"
Click="Button_Click"
Content="找回密码"
IsEnabled="False" />
</StackPanel>
<TeachingTip Name="Toast" CloseButtonContent="关闭" />
</Grid>
</UserControl>

View File

@ -0,0 +1,106 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Newtonsoft.Json;
using RustTools.DataList;
using WinUIEx.Messaging;
namespace RustTools.Themes;
/// <summary>
/// 找回密码
/// </summary>
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;
}
/// <summary>
/// 发送验证码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<DataList.Message>(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);
/// <summary>
/// 找回密码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<DataList.Message>(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();
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
namespace RustTools.ViewModels;
public class CodeTableViewModel : ObservableRecipient
{
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page
x:Class="RustTools.Views.CodeTablePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:RustTools.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid />
</Page>

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace RustTools.Views;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class CodeTablePage : Page
{
public CodeTablePage()
{
this.InitializeComponent();
}
}

View File

@ -37,10 +37,11 @@ public sealed partial class ShellPage : Page
// TODO: Set the title bar icon by updating /Assets/WindowIcon.ico.
// A custom title bar is required for full window theme and Mica support.
// https://docs.microsoft.com/windows/apps/develop/title-bar?tabs=winui3#full-customization
App.MainWindow.ExtendsContentIntoTitleBar = true;
if (App.MainWindow != null)
{
App.MainWindow.SetTitleBar(AppTitleBar);
App.MainWindow.Activated += MainWindow_Activated;
App.MainWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
}
AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized();
}
@ -55,7 +56,7 @@ public sealed partial class ShellPage : Page
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
{
App.AppTitlebar = AppTitleBarText as UIElement;
App.AppTitlebar = AppTitleBarText;
}
private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)

View File

@ -53,10 +53,9 @@ public sealed partial class UserPage : Page
await login(account);
}
}
catch (Exception ex)
catch
{
nulllogin();
gj.sc(ex);
}
}
private void nulllogin()
@ -75,7 +74,6 @@ public sealed partial class UserPage : Page
view.Children.Remove((LoginPage)sender);
await login(account);
}
public string aaa { get; set; } = "aaa";
private async Task login(string account)
{
@ -86,7 +84,6 @@ public sealed partial class UserPage : Page
var data = userSpaceInfo.Data;
if (data == null) { return; }
data.HeadIcon=data.HeadIcon == string.Empty ? "/Assets/tool.png" : data.HeadIcon.Replace("..", wl.api);
gj.sc(data.HeadIcon);
userInfo = data;
DataContext = this;

View File

@ -12,57 +12,50 @@
Closed="WindowEx_Closed"
SizeChanged="WindowEx_SizeChanged"
mc:Ignorable="d">
<Grid x:Name="grid"
Padding="16,36,16,10">
<Grid x:Name="grid" Padding="16,36,16,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions/>
<StackPanel Grid.Row="0"
Orientation="Horizontal">
<Grid.ColumnDefinitions />
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Border
Width="106"
Height="106"
CornerRadius="9">
<Border.Background>
<ImageBrush ImageSource="{Binding Mod.IconUrl}"
Stretch="UniformToFill"/>
<ImageBrush ImageSource="{Binding Mod.IconUrl}" Stretch="UniformToFill" />
</Border.Background>
</Border>
<StackPanel Margin="16,3,9,3"
Orientation="Vertical">
<TextBlock Style="{StaticResource TitleLargeTextBlockStyle}"
Text="{Binding Mod.Name}"/>
<StackPanel Margin="16,3,9,3" Orientation="Vertical">
<TextBlock Style="{StaticResource TitleLargeTextBlockStyle}" Text="{Binding Mod.Name}" />
<TextBlock
x:Name="title_b"
Margin="0,3,0,0"
Style="{StaticResource BodyTextBlockStyle}"
Text="加载中"/>
Text="加载中" />
<TextBlock
x:Name="title_c"
Margin="0,9,0,0"
Style="{StaticResource BodyTextBlockStyle}"
Text="加载中"/>
Text="加载中" />
</StackPanel>
</StackPanel>
<ScrollView Grid.Row="1">
<StackPanel Margin="0,26,0,0"
Orientation="Vertical">
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}"
Text="介绍"/>
<StackPanel Margin="0,26,0,0" Orientation="Vertical">
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="介绍" />
<TextBlock
x:Name="DescriptionText"
Padding="6,6,6,6"
Style="{StaticResource BodyTextBlockStyle}"
Text="{Binding Mod.Description}"
TextWrapping="Wrap"/>
TextWrapping="Wrap" />
<TextBlock
x:Name="fliptext"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="截图"
Visibility="Collapsed"/>
Visibility="Collapsed" />
<FlipView
x:Name="flipview"
MaxWidth="600"
@ -73,8 +66,7 @@
Visibility="Collapsed">
<FlipView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<Image Source="{x:Bind Mode=OneTime}"
Stretch="Uniform"/>
<Image Source="{x:Bind Mode=OneTime}" Stretch="Uniform" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
@ -91,19 +83,19 @@
Name="ReportButton"
Click="AppBarButton_Click"
Icon="ReportHacked"
Label="举报"/>
<AppBarSeparator/>
Label="举报" />
<AppBarSeparator />
<AppBarButton
Name="LikeButton"
Click="AppBarButton_Click"
Icon="Like"
Label="支持"/>
<AppBarSeparator/>
Label="支持" />
<AppBarSeparator />
<AppBarButton
Name="DownLoadButton"
Click="AppBarButton_Click"
Icon="Download"
Label="下载"/>
Label="下载" />
</CommandBar.PrimaryCommands>
</CommandBar>
<TeachingTip
@ -115,18 +107,7 @@
IsLightDismissEnabled="True"
PlacementMargin="20"
PreferredPlacement="Auto"
Subtitle="消息"/>
Subtitle="消息" />
<ContentDialog
x:Name="DownloadDialog"
Title="下载中"
SecondaryButtonText="取消">
<StackPanel>
<TextBlock Name="DownloadDialogText"
Text="下载完成后会自动导入到你配置的模组路径,请勿取消"/>
<ProgressBar Margin="0,6,0,0"
IsIndeterminate="True"/>
</StackPanel>
</ContentDialog>
</Grid>
</windowex:WindowEx>

View File

@ -114,6 +114,13 @@ public sealed partial class ModuleInfoWin : WindowEx
break;
case "DownLoadButton":
DownMod();
break;
}
}
private async void DownMod()
{
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.Config);
var v = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);
@ -131,6 +138,22 @@ public sealed partial class ModuleInfoWin : WindowEx
return;
}
var DownloadDialog = new ContentDialog()
{
XamlRoot = grid.XamlRoot,
Title = "下载",
SecondaryButtonText = "取消"
};
var stack = new StackPanel();
var textBlock = new TextBlock();
stack.Children.Add(textBlock);
stack.Children.Add(new ProgressBar
{
Margin = new Thickness(0, 6, 0, 0),
IsIndeterminate = true
});
DownloadDialog.Content =stack;
var cancellationTokenSource = new CancellationTokenSource();
gj.sc("下载此模组:" + Mod.Link);
var downloader = new FileDownloader();
@ -145,7 +168,13 @@ public sealed partial class ModuleInfoWin : WindowEx
};
try
{
var PathMod = Path.Combine(v, Mod.Name);
var name = Mod.Name;//把非法字符替换掉
var invalidChars = Path.GetInvalidFileNameChars();
foreach (var a in invalidChars)
{
name = name.Replace(a.ToString(), "_");//把非法字符替换掉
}
var PathMod = Path.Combine(v, name);
if (File.Exists(PathMod + ".rwmod"))
{
File.Delete(PathMod + ".rwmod");
@ -153,12 +182,16 @@ public sealed partial class ModuleInfoWin : WindowEx
//下载链接 保存文件的本地路径
await downloader.DownloadFileAsync(Mod.Link, PathMod, (totalBytesRead, totalBytes) =>
{
DownloadDialogText.Text = $"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete.";
//Debug.WriteLine($"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete.");
//DownloadDialogText.Text = $"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete.";
textBlock.Text = $"下载进度:{(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}%";
}, cancellationTokenSource.Token);
Debug.WriteLine("文件下载完成");
File.Move(PathMod, PathMod + ".rwmod");
textBlock.Text = "文件下载完成";
DownloadDialog.Closing -= DownloadDialog_Closing;
DownloadDialog.IsSecondaryButtonEnabled = false;
await Task.Delay(1500);
// 手动隐藏对话框
DownloadDialog.Hide();
@ -172,10 +205,13 @@ public sealed partial class ModuleInfoWin : WindowEx
DownloadDialog.Closing -= DownloadDialog_Closing;
DownloadDialog.Hide();
}
break;
}
}
/// <summary>
/// 底部提示确定按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void Toast_ActionButtonClick(TeachingTip sender, object args)
{

View File

@ -96,10 +96,10 @@ class wl
}
}
//if (IsDelete)
//{
// File.Delete(savePath);
//}
if (IsDelete)
{
File.Delete(savePath);
}
}
}