Next push
This commit is contained in:
@@ -150,6 +150,9 @@
|
||||
<Compile Include="Models\User.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\SessionWindow.xaml.cs">
|
||||
<DependentUpon>SessionWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Page Include="Views\MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
@@ -158,10 +161,15 @@
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\SessionModel.cs" />
|
||||
<Compile Include="Views\MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="Views\SessionWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Wpf.Ui.Input;
|
||||
using Labaratory.ViewModels;
|
||||
using Labaratory.Views;
|
||||
|
||||
namespace Labaratory
|
||||
{
|
||||
@@ -16,19 +18,29 @@ namespace Labaratory
|
||||
private string _password;
|
||||
private string _captchaText;
|
||||
private string _captchaInput;
|
||||
private bool _isCaptchaVisible;
|
||||
private bool _isCaptchaValid;
|
||||
private bool _isLoginEnabled = true;
|
||||
private int _failedAttempts = 0;
|
||||
private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities();
|
||||
|
||||
private Visibility _CapchaVisibility = Visibility.Hidden;
|
||||
|
||||
// Свойства для привязки (Binding)
|
||||
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 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 Visibility CapchaVisibility { get => _CapchaVisibility; set { _CapchaVisibility = value; OnPropertyChanged(); } }
|
||||
|
||||
// Команды
|
||||
public ICommand LoginCommand { get; }
|
||||
@@ -36,7 +48,9 @@ namespace Labaratory
|
||||
|
||||
public LoginViewModel()
|
||||
{
|
||||
LoginCommand = new RelayCommand<object>(execute => ExecuteLogin());
|
||||
LoginCommand = new RelayCommand<object>(
|
||||
execute => ExecuteLogin(execute),
|
||||
canExecute => IsLoginEnabled);
|
||||
RefreshCaptchaCommand = new RelayCommand<object>(execute => GenerateNewCaptcha());
|
||||
}
|
||||
|
||||
@@ -46,9 +60,9 @@ namespace Labaratory
|
||||
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("Неверная капча!");
|
||||
GenerateNewCaptcha();
|
||||
@@ -56,14 +70,27 @@ namespace Labaratory
|
||||
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
|
||||
{
|
||||
MessageBox.Show("Неверный логин или пароль");
|
||||
IsCaptchaVisible = true;
|
||||
CapchaVisibility = Visibility.Visible;
|
||||
GenerateNewCaptcha();
|
||||
}
|
||||
}
|
||||
|
||||
22
Labaratory/Labaratory/ViewModels/SessionModel.cs
Normal file
22
Labaratory/Labaratory/ViewModels/SessionModel.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,19 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Labaratory"
|
||||
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"
|
||||
Title="MainWindow" Height="450" Width="400"
|
||||
Title="MainWindow" Height="500" Width="400"
|
||||
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
|
||||
Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}">
|
||||
|
||||
<Grid>
|
||||
<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="96*"></RowDefinition>
|
||||
<RowDefinition Height="82*"></RowDefinition>
|
||||
<RowDefinition Height="79*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0" Margin="10,10,10,10">
|
||||
@@ -29,15 +30,20 @@
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1" Margin="10,10,10,10">
|
||||
<ui:TextBlock Text="Введите логин" Margin="10"/>
|
||||
<ui:TextBox Width="220" PlaceholderText="Логин"/>
|
||||
<ui:TextBox Width="220" PlaceholderText="Логин" Text="{Binding Login}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Margin="10,10,10,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 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"/>
|
||||
<Grid HorizontalAlignment="Left" Margin="10,0,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -45,12 +51,12 @@
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</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">
|
||||
<ui:TextBlock x:Name="CaptchaVisual"
|
||||
Text="A1B2C"
|
||||
Text="{Binding CaptchaText}"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
FontStyle="Italic"
|
||||
@@ -64,11 +70,17 @@
|
||||
Icon="ArrowClockwise24"
|
||||
Appearance="Transparent"
|
||||
Content="Новая капча"
|
||||
Click="RefreshCaptcha_Click"/>
|
||||
Command="{Binding RefreshCaptchaCommand}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="4" Margin="10">
|
||||
<ui:Button Width="220" Content="Войти" HorizontalAlignment="Center" Margin="0,15,0,0" Click="LoginButton_Click"/>
|
||||
<StackPanel Grid.Row="4" Margin="10,10,10,10" Cursor="">
|
||||
<ui:Button
|
||||
Width="220"
|
||||
Content="Войти"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,15,0,0"
|
||||
Command="{Binding LoginCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -21,46 +21,17 @@ namespace Labaratory
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private string _activeCaptcha;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
LaboratoryDBEntities db = new LaboratoryDBEntities();
|
||||
InitializeComponent();
|
||||
DataContext = new LoginViewModel();
|
||||
this.DataContext = new LoginViewModel();
|
||||
}
|
||||
private void RefreshCaptcha_Click(object sender, RoutedEventArgs e)
|
||||
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void LoginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CaptchaInput.Visibility != Visibility.Visible)
|
||||
if (this.DataContext is LoginViewModel vm)
|
||||
{
|
||||
Login();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Неверный логин или пароль!");
|
||||
//GenerateCaptcha();
|
||||
}
|
||||
|
||||
if (CaptchaInput.Visibility != Visibility.Visible)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Неверная капча!");
|
||||
//GenerateCaptcha();
|
||||
vm.Password = passwordbox.Password;
|
||||
}
|
||||
}
|
||||
private bool Login()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
12
Labaratory/Labaratory/Views/SessionWindow.xaml
Normal file
12
Labaratory/Labaratory/Views/SessionWindow.xaml
Normal 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>
|
||||
27
Labaratory/Labaratory/Views/SessionWindow.xaml.cs
Normal file
27
Labaratory/Labaratory/Views/SessionWindow.xaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user