Next push

This commit is contained in:
oreshki
2026-04-08 16:18:28 +05:00
parent 5274f8ed3f
commit 7e83e56be6
7 changed files with 137 additions and 58 deletions

View File

@@ -150,6 +150,9 @@
<Compile Include="Models\User.cs"> <Compile Include="Models\User.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\SessionWindow.xaml.cs">
<DependentUpon>SessionWindow.xaml</DependentUpon>
</Compile>
<Page Include="Views\MainWindow.xaml"> <Page Include="Views\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -158,10 +161,15 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ViewModels\SessionModel.cs" />
<Compile Include="Views\MainWindow.xaml.cs"> <Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="Views\SessionWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">

View File

@@ -7,6 +7,8 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Wpf.Ui.Input; using Wpf.Ui.Input;
using Labaratory.ViewModels;
using Labaratory.Views;
namespace Labaratory namespace Labaratory
{ {
@@ -16,19 +18,29 @@ namespace Labaratory
private string _password; private string _password;
private string _captchaText; private string _captchaText;
private string _captchaInput; private string _captchaInput;
private bool _isCaptchaVisible; private bool _isCaptchaValid;
private bool _isLoginEnabled = true; private bool _isLoginEnabled = true;
private int _failedAttempts = 0; private int _failedAttempts = 0;
private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities(); private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities();
private Visibility _CapchaVisibility = Visibility.Hidden;
// Свойства для привязки (Binding) // Свойства для привязки (Binding)
public string Login { get => _login; set { _login = value; OnPropertyChanged(); } } public string Login { get => _login; set { _login = value; OnPropertyChanged(); } }
public string Password { get => _password; set { _password = value; OnPropertyChanged(); } } public string Password
{
get => _password;
set
{
if (_password == value) return; // Обязательно!
_password = value;
OnPropertyChanged();
}
}
public string CaptchaText { get => _captchaText; set { _captchaText = value; OnPropertyChanged(); } } public string CaptchaText { get => _captchaText; set { _captchaText = value; OnPropertyChanged(); } }
public string CaptchaInput { get => _captchaInput; set { _captchaInput = value; OnPropertyChanged(); } } public string CaptchaInput { get => _captchaInput; set { _captchaInput = value; OnPropertyChanged(); } }
public bool IsCaptchaVisible { get => _isCaptchaVisible; set { _isCaptchaVisible = value; OnPropertyChanged(); } } public bool IsCaptchaValid { get => _isCaptchaValid; set { _isCaptchaValid = value; OnPropertyChanged(); } }
public bool IsLoginEnabled { get => _isLoginEnabled; set { _isLoginEnabled = value; OnPropertyChanged(); } } public bool IsLoginEnabled { get => _isLoginEnabled; set { _isLoginEnabled = value; OnPropertyChanged(); } }
public Visibility CapchaVisibility { get => _CapchaVisibility; set { _CapchaVisibility = value; OnPropertyChanged(); } }
// Команды // Команды
public ICommand LoginCommand { get; } public ICommand LoginCommand { get; }
@@ -36,7 +48,9 @@ namespace Labaratory
public LoginViewModel() public LoginViewModel()
{ {
LoginCommand = new RelayCommand<object>(execute => ExecuteLogin()); LoginCommand = new RelayCommand<object>(
execute => ExecuteLogin(execute),
canExecute => IsLoginEnabled);
RefreshCaptchaCommand = new RelayCommand<object>(execute => GenerateNewCaptcha()); RefreshCaptchaCommand = new RelayCommand<object>(execute => GenerateNewCaptcha());
} }
@@ -46,24 +60,37 @@ namespace Labaratory
CaptchaInput = string.Empty; CaptchaInput = string.Empty;
} }
private async void ExecuteLogin() private async void ExecuteLogin(object parameter)
{ {
if (IsCaptchaVisible && !Valid.ValidateCaptcha(CaptchaInput, CaptchaText)) if (CapchaVisibility == Visibility.Visible && !Valid.ValidateCaptcha(CaptchaInput, CaptchaText))
{ {
MessageBox.Show("Неверная капча!"); MessageBox.Show("Неверная капча!");
GenerateNewCaptcha(); GenerateNewCaptcha();
await LockSystem(10); //Блокировка на 10 сек await LockSystem(10); //Блокировка на 10 сек
return; return;
} }
if (Login == "admin" && Password == "123") var user = db.Users.FirstOrDefault(u => u.Login == Login && u.Password == Password);
if (user != null)
{ {
MessageBox.Show("Успешный вход!"); MessageBox.Show($"Успешный вход! Добро пожаловать, {user.Login}");
if (parameter is Window window)
{
var nextWindow = new SessionWindow();
var mainVM = new SessionModel(user);
// Привязываем VM к окну
nextWindow.DataContext = mainVM;
nextWindow.Show();
window.Close();
}
} }
else else
{ {
MessageBox.Show("Неверный логин или пароль"); MessageBox.Show("Неверный логин или пароль");
IsCaptchaVisible = true; CapchaVisibility = Visibility.Visible;
GenerateNewCaptcha(); GenerateNewCaptcha();
} }
} }

View File

@@ -0,0 +1,22 @@
using Labaratory.Services;
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Wpf.Ui.Input;
namespace Labaratory.ViewModels
{
public class SessionModel : BaseViewModel
{
public Models.User CurrentUser { get; set; }
public SessionModel(Models.User user)
{
CurrentUser = user;
}
}
}

View File

@@ -5,18 +5,19 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Labaratory" xmlns:local="clr-namespace:Labaratory"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" x:Class="Labaratory.MainWindow" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" x:Class="Labaratory.MainWindow"
xmlns:easy ="clr-namespace:EasyCaptcha.Wpf;assembly=EasyCaptcha.Wpf" xmlns:easy ="clr-namespace:EasyCaptcha.Wpf;assembly=EasyCaptcha.Wpf" d:DataContext="{d:DesignInstance Type=local:LoginViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="400" Title="MainWindow" Height="500" Width="400"
Background="{ui:ThemeResource ApplicationBackgroundBrush}" Background="{ui:ThemeResource ApplicationBackgroundBrush}"
Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}"> Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="81*"></RowDefinition> <RowDefinition Height="86*"></RowDefinition>
<RowDefinition Height="101*"></RowDefinition>
<RowDefinition Height="108*"></RowDefinition>
<RowDefinition Height="93*"></RowDefinition>
<RowDefinition Height="97*"></RowDefinition> <RowDefinition Height="97*"></RowDefinition>
<RowDefinition Height="96*"></RowDefinition>
<RowDefinition Height="82*"></RowDefinition>
<RowDefinition Height="79*"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="10,10,10,10"> <StackPanel Grid.Row="0" Margin="10,10,10,10">
@@ -29,15 +30,20 @@
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Margin="10,10,10,10"> <StackPanel Grid.Row="1" Margin="10,10,10,10">
<ui:TextBlock Text="Введите логин" Margin="10"/> <ui:TextBlock Text="Введите логин" Margin="10"/>
<ui:TextBox Width="220" PlaceholderText="Логин"/> <ui:TextBox Width="220" PlaceholderText="Логин" Text="{Binding Login}"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="2" Margin="10,10,10,10"> <StackPanel Grid.Row="2" Margin="10,10,10,10">
<ui:TextBlock Text="Введите пароль" Margin="10"/> <ui:TextBlock Text="Введите пароль" Margin="10"/>
<ui:PasswordBox PlaceholderText="Пароль" Width="220"/> <ui:PasswordBox
PlaceholderText="Пароль"
Width="220"
Cursor="IBeam"
PasswordChanged="PasswordBox_PasswordChanged"
Name="passwordbox"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="3" Margin="10,10,10,10"> <StackPanel Grid.Row="3" Margin="10,10,10,10" Visibility="{Binding CapchaVisibility}">
<ui:TextBlock Text="Введите код с картинки" Margin="10,0,0,5"/> <ui:TextBlock Text="Введите код с картинки" Margin="10,0,0,5"/>
<Grid HorizontalAlignment="Left" Margin="10,0,0,0"> <Grid HorizontalAlignment="Left" Margin="10,0,0,0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -45,12 +51,12 @@
<ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ui:TextBox x:Name="CaptchaInput" Grid.Column="0" PlaceholderText="Код"/> <ui:TextBox x:Name="CaptchaInput" Grid.Column="0" PlaceholderText="Код" Text="{Binding CaptchaInput}"/>
<Border Grid.Column="1" Margin="5,0" Background="#1A000000" CornerRadius="4"> <Border Grid.Column="1" Margin="5,0" Background="#1A000000" CornerRadius="4">
<ui:TextBlock x:Name="CaptchaVisual" <ui:TextBlock x:Name="CaptchaVisual"
Text="A1B2C" Text="{Binding CaptchaText}"
FontSize="20" FontSize="20"
FontWeight="Bold" FontWeight="Bold"
FontStyle="Italic" FontStyle="Italic"
@@ -64,11 +70,17 @@
Icon="ArrowClockwise24" Icon="ArrowClockwise24"
Appearance="Transparent" Appearance="Transparent"
Content="Новая капча" Content="Новая капча"
Click="RefreshCaptcha_Click"/> Command="{Binding RefreshCaptchaCommand}"/>
</Grid> </Grid>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="4" Margin="10"> <StackPanel Grid.Row="4" Margin="10,10,10,10" Cursor="">
<ui:Button Width="220" Content="Войти" HorizontalAlignment="Center" Margin="0,15,0,0" Click="LoginButton_Click"/> <ui:Button
Width="220"
Content="Войти"
HorizontalAlignment="Center"
Margin="0,15,0,0"
Command="{Binding LoginCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Window> </Window>

View File

@@ -21,46 +21,17 @@ namespace Labaratory
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private string _activeCaptcha;
public MainWindow() public MainWindow()
{ {
LaboratoryDBEntities db = new LaboratoryDBEntities();
InitializeComponent(); InitializeComponent();
DataContext = new LoginViewModel(); this.DataContext = new LoginViewModel();
} }
private void RefreshCaptcha_Click(object sender, RoutedEventArgs e) private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{ {
if (this.DataContext is LoginViewModel vm)
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
if (CaptchaInput.Visibility != Visibility.Visible)
{ {
Login(); vm.Password = passwordbox.Password;
}
else
{
MessageBox.Show("Неверный логин или пароль!");
//GenerateCaptcha();
}
if (CaptchaInput.Visibility != Visibility.Visible)
{
}
else
{
MessageBox.Show("Неверная капча!");
//GenerateCaptcha();
} }
} }
private bool Login()
{
return false;
}
} }
} }

View File

@@ -0,0 +1,12 @@
<Window x:Class="Labaratory.Views.SessionWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Labaratory.Views"
mc:Ignorable="d"
Title="SessionWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Labaratory.Views
{
/// <summary>
/// Логика взаимодействия для SessionWindow.xaml
/// </summary>
public partial class SessionWindow : Window
{
public SessionWindow()
{
InitializeComponent();
}
}
}