improve:安全面板
This commit is contained in:
@@ -57,6 +57,16 @@ namespace Ink_Canvas.Helpers
|
||||
public static bool IsPasswordRequiredForResetConfig(Settings settings)
|
||||
=> IsPasswordFeatureEnabled(settings) && HasPasswordConfigured(settings) && settings.Security.RequirePasswordOnResetConfig;
|
||||
|
||||
/// <summary>
|
||||
/// 指示在修改或清空点名名单前是否需要输入安全密码。
|
||||
/// </summary>
|
||||
/// <param name="settings">应用设置对象。</param>
|
||||
/// <returns>当已启用密码功能、已配置密码且开启了对应开关时返回 true;否则返回 false。</returns>
|
||||
public static bool IsPasswordRequiredForModifyOrClearNameList(Settings settings)
|
||||
=> IsPasswordFeatureEnabled(settings)
|
||||
&& HasPasswordConfigured(settings)
|
||||
&& settings.Security.RequirePasswordOnModifyOrClearNameList;
|
||||
|
||||
/// <summary>
|
||||
/// 将提供的明文密码与 Settings 中存储的密码散列进行比对以验证密码是否正确。
|
||||
/// </summary>
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace Ink_Canvas
|
||||
public bool RequirePasswordOnEnterSettings { get; set; } = false;
|
||||
[JsonProperty("requirePasswordOnResetConfig")]
|
||||
public bool RequirePasswordOnResetConfig { get; set; } = false;
|
||||
[JsonProperty("requirePasswordOnModifyOrClearNameList")]
|
||||
public bool RequirePasswordOnModifyOrClearNameList { get; set; } = false;
|
||||
[JsonProperty("enableProcessProtection")]
|
||||
public bool EnableProcessProtection { get; set; } = true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -1200,10 +1200,19 @@ namespace Ink_Canvas
|
||||
UpdateCountDisplay();
|
||||
}
|
||||
|
||||
private void ImportList_Click(object sender, RoutedEventArgs e)
|
||||
private async void ImportList_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SecurityManager.IsPasswordRequiredForModifyOrClearNameList(MainWindow.Settings))
|
||||
{
|
||||
bool ok = await SecurityManager.PromptAndVerifyAsync(
|
||||
MainWindow.Settings,
|
||||
this,
|
||||
"名单修改验证",
|
||||
"请输入安全密码以修改点名名单。");
|
||||
if (!ok) return;
|
||||
}
|
||||
// 打开名单导入窗口,与老点名UI保持一致
|
||||
var namesInputWindow = new NamesInputWindow();
|
||||
namesInputWindow.ShowDialog();
|
||||
@@ -1260,10 +1269,19 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearList_Click(object sender, RoutedEventArgs e)
|
||||
private async void ClearList_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SecurityManager.IsPasswordRequiredForModifyOrClearNameList(MainWindow.Settings))
|
||||
{
|
||||
bool ok = await SecurityManager.PromptAndVerifyAsync(
|
||||
MainWindow.Settings,
|
||||
this,
|
||||
"名单清空验证",
|
||||
"请输入安全密码以清空点名名单。");
|
||||
if (!ok) return;
|
||||
}
|
||||
// 清空名单
|
||||
nameList.Clear();
|
||||
UpdateListCountDisplay();
|
||||
|
||||
@@ -390,8 +390,18 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void BorderBtnHelp_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
private async void BorderBtnHelp_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (SecurityManager.IsPasswordRequiredForModifyOrClearNameList(MainWindow.Settings))
|
||||
{
|
||||
bool ok = await SecurityManager.PromptAndVerifyAsync(
|
||||
MainWindow.Settings,
|
||||
this,
|
||||
"名单修改验证",
|
||||
"请输入安全密码以修改点名名单。");
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
new NamesInputWindow().ShowDialog();
|
||||
Window_Loaded(this, null);
|
||||
}
|
||||
|
||||
@@ -116,6 +116,20 @@
|
||||
</Border>
|
||||
</Border>
|
||||
</Grid>
|
||||
<Border Height="1" Background="#ebebeb" Margin="0,8,0,8"/>
|
||||
<Grid Height="54">
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Left">
|
||||
<TextBlock Foreground="#2e3436" FontSize="14.5" Text="修改/清空点名名单需要密码" HorizontalAlignment="Left"/>
|
||||
<TextBlock Foreground="#9a9996" FontSize="11" Margin="0,3.5,0,0" Text="在修改名单或清空名单前进行密码验证" HorizontalAlignment="Left"/>
|
||||
</StackPanel>
|
||||
<Border x:Name="ToggleSwitchRequirePasswordOnModifyOrClearNameList" Style="{StaticResource ToggleSwitchStyle}" Background="#e1e1e1" Tag="RequirePasswordOnModifyOrClearNameList" MouseLeftButtonDown="ToggleSwitch_Click">
|
||||
<Border Width="19" Height="19" Background="White" CornerRadius="10" HorizontalAlignment="Left" VerticalAlignment="Center">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect BlurRadius="4" Direction="-45" Color="Black" Opacity="0.3" ShadowDepth="0"/>
|
||||
</Border.Effect>
|
||||
</Border>
|
||||
</Border>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
@@ -144,4 +158,3 @@
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</local:SettingsPanelBase>
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchRequirePasswordOnExit"), sec.RequirePasswordOnExit);
|
||||
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchRequirePasswordOnEnterSettings"), sec.RequirePasswordOnEnterSettings);
|
||||
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchRequirePasswordOnResetConfig"), sec.RequirePasswordOnResetConfig);
|
||||
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchRequirePasswordOnModifyOrClearNameList"), sec.RequirePasswordOnModifyOrClearNameList);
|
||||
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableProcessProtection"), sec.EnableProcessProtection);
|
||||
|
||||
UpdatePasswordUiState();
|
||||
@@ -65,9 +66,11 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
var t1 = FindToggleSwitch("ToggleSwitchRequirePasswordOnExit");
|
||||
var t2 = FindToggleSwitch("ToggleSwitchRequirePasswordOnEnterSettings");
|
||||
var t3 = FindToggleSwitch("ToggleSwitchRequirePasswordOnResetConfig");
|
||||
var t4 = FindToggleSwitch("ToggleSwitchRequirePasswordOnModifyOrClearNameList");
|
||||
if (t1 != null) t1.IsEnabled = usageEnabled;
|
||||
if (t2 != null) t2.IsEnabled = usageEnabled;
|
||||
if (t3 != null) t3.IsEnabled = usageEnabled;
|
||||
if (t4 != null) t4.IsEnabled = usageEnabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,6 +146,10 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
sec.RequirePasswordOnResetConfig = newState;
|
||||
MainWindow.SaveSettingsToFile();
|
||||
break;
|
||||
case "RequirePasswordOnModifyOrClearNameList":
|
||||
sec.RequirePasswordOnModifyOrClearNameList = newState;
|
||||
MainWindow.SaveSettingsToFile();
|
||||
break;
|
||||
case "EnableProcessProtection":
|
||||
sec.EnableProcessProtection = newState;
|
||||
MainWindow.SaveSettingsToFile();
|
||||
|
||||
Reference in New Issue
Block a user