Better model getting point how it works
This commit is contained in:
@@ -13,6 +13,6 @@
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<connectionStrings>
|
||||
<add name="LaboratoryDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=PC311-11;initial catalog=LaboratoryDB;integrated security=True;trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
|
||||
<add name="LaboratoryDBEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=PC311-11;initial catalog=LaboratoryDB;integrated security=True;trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
|
||||
</connectionStrings>
|
||||
</configuration>
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Labaratory" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
StartupUri="Views/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@@ -89,67 +89,68 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Analyzer.cs">
|
||||
<Compile Include="Models\Analyzer.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Analyzer_Logs.cs">
|
||||
<Compile Include="Models\Analyzer_Logs.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseViewModel.cs" />
|
||||
<Compile Include="Insurance_Companies.cs">
|
||||
<Compile Include="Services\Valid.cs" />
|
||||
<Compile Include="ViewModels\BaseViewModel.cs" />
|
||||
<Compile Include="Models\Insurance_Companies.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Invoice.cs">
|
||||
<Compile Include="Models\Invoice.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="LoginViewModel.cs" />
|
||||
<Compile Include="Model1.Context.cs">
|
||||
<Compile Include="ViewModels\LoginViewModel.cs" />
|
||||
<Compile Include="Models\Model1.Context.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Model1.Context.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model1.cs">
|
||||
<Compile Include="Models\Model1.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model1.Designer.cs">
|
||||
<Compile Include="Models\Model1.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Model1.edmx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Order.cs">
|
||||
<Compile Include="Models\Order.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Order_Items.cs">
|
||||
<Compile Include="Models\Order_Items.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Order_Statuses.cs">
|
||||
<Compile Include="Models\Order_Statuses.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Patient.cs">
|
||||
<Compile Include="Models\Patient.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Policy_Types.cs">
|
||||
<Compile Include="Models\Policy_Types.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Rendered_Services.cs">
|
||||
<Compile Include="Models\Rendered_Services.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Role.cs">
|
||||
<Compile Include="Models\Role.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Service.cs">
|
||||
<Compile Include="Models\Service.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Service_Statuses.cs">
|
||||
<Compile Include="Models\Service_Statuses.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="SessionManager.cs" />
|
||||
<Compile Include="User.cs">
|
||||
<Compile Include="Services\SessionManager.cs" />
|
||||
<Compile Include="Models\User.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Page Include="Views\MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
@@ -157,7 +158,7 @@
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<Compile Include="Views\MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -180,11 +181,11 @@
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EntityDeploy Include="Model1.edmx">
|
||||
<EntityDeploy Include="Models\Model1.edmx">
|
||||
<Generator>EntityModelCodeGenerator</Generator>
|
||||
<LastGenOutput>Model1.Designer.cs</LastGenOutput>
|
||||
</EntityDeploy>
|
||||
<None Include="Model1.edmx.diagram">
|
||||
<None Include="Models\Model1.edmx.diagram">
|
||||
<DependentUpon>Model1.edmx</DependentUpon>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
@@ -197,12 +198,12 @@
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Model1.Context.tt">
|
||||
<Content Include="Models\Model1.Context.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>Model1.Context.cs</LastGenOutput>
|
||||
<DependentUpon>Model1.edmx</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="Model1.tt">
|
||||
<Content Include="Models\Model1.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<DependentUpon>Model1.edmx</DependentUpon>
|
||||
<LastGenOutput>Model1.cs</LastGenOutput>
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Labaratory
|
||||
{
|
||||
public class LoginViewModel : BaseViewModel
|
||||
{
|
||||
private string _login;
|
||||
private string _captchaText;
|
||||
private bool _isCaptchaVisible;
|
||||
|
||||
public string Login
|
||||
{
|
||||
get => _login;
|
||||
set { _login = value; OnPropertyChanged(); }
|
||||
}
|
||||
|
||||
public bool IsCaptchaVisible
|
||||
{
|
||||
get => _isCaptchaVisible;
|
||||
set { _isCaptchaVisible = value; OnPropertyChanged(); }
|
||||
}
|
||||
|
||||
public ICommand LoginCommand { get; }
|
||||
|
||||
public LoginViewModel()
|
||||
{
|
||||
// Инициализация команд и капчи
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
@@ -1,4 +1,4 @@
|
||||
// Создание кода T4 для модели "C:\Users\usersql\source\repos\UP01TASK3\Labaratory\Labaratory\Model1.edmx" включено.
|
||||
// Создание кода T4 для модели "C:\Users\usersql\source\repos\UP01TASK3\Labaratory\Labaratory\Models\Model1.edmx" включено.
|
||||
// Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
|
||||
// на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
|
||||
// открыта в конструкторе.
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,7 +7,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Labaratory
|
||||
namespace Labaratory.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
30
Labaratory/Labaratory/Services/Valid.cs
Normal file
30
Labaratory/Labaratory/Services/Valid.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Labaratory.Services
|
||||
{
|
||||
public static class Valid
|
||||
{
|
||||
public static string GenerateCaptchaText()
|
||||
{
|
||||
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
Random rand = new Random();
|
||||
return new string(Enumerable.Repeat(chars, 4)
|
||||
.Select(s => s[rand.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
public static bool IsPasswordStrong(string password)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ValidateCaptcha(string input, string original)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return false;
|
||||
return input.Trim().ToUpper() == original.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
78
Labaratory/Labaratory/ViewModels/LoginViewModel.cs
Normal file
78
Labaratory/Labaratory/ViewModels/LoginViewModel.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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
|
||||
{
|
||||
public class LoginViewModel : BaseViewModel
|
||||
{
|
||||
private string _login;
|
||||
private string _password;
|
||||
private string _captchaText;
|
||||
private string _captchaInput;
|
||||
private bool _isCaptchaVisible;
|
||||
private bool _isLoginEnabled = true;
|
||||
private int _failedAttempts = 0;
|
||||
private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities();
|
||||
|
||||
|
||||
// Свойства для привязки (Binding)
|
||||
public string Login { get => _login; set { _login = value; OnPropertyChanged(); } }
|
||||
public string Password { get => _password; set { _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 IsLoginEnabled { get => _isLoginEnabled; set { _isLoginEnabled = value; OnPropertyChanged(); } }
|
||||
|
||||
// Команды
|
||||
public ICommand LoginCommand { get; }
|
||||
public ICommand RefreshCaptchaCommand { get; }
|
||||
|
||||
public LoginViewModel()
|
||||
{
|
||||
LoginCommand = new RelayCommand<object>(execute => ExecuteLogin());
|
||||
RefreshCaptchaCommand = new RelayCommand<object>(execute => GenerateNewCaptcha());
|
||||
}
|
||||
|
||||
private void GenerateNewCaptcha()
|
||||
{
|
||||
CaptchaText = Valid.GenerateCaptchaText();
|
||||
CaptchaInput = string.Empty;
|
||||
}
|
||||
|
||||
private async void ExecuteLogin()
|
||||
{
|
||||
if (IsCaptchaVisible && !Valid.ValidateCaptcha(CaptchaInput, CaptchaText))
|
||||
{
|
||||
MessageBox.Show("Неверная капча!");
|
||||
GenerateNewCaptcha();
|
||||
await LockSystem(10); //Блокировка на 10 сек
|
||||
return;
|
||||
}
|
||||
|
||||
if (Login == "admin" && Password == "123")
|
||||
{
|
||||
MessageBox.Show("Успешный вход!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Неверный логин или пароль");
|
||||
IsCaptchaVisible = true;
|
||||
GenerateNewCaptcha();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LockSystem(int seconds)
|
||||
{
|
||||
IsLoginEnabled = false;
|
||||
await Task.Delay(TimeSpan.FromSeconds(seconds));
|
||||
IsLoginEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Labaratory.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -28,34 +29,22 @@ namespace Labaratory
|
||||
InitializeComponent();
|
||||
DataContext = new LoginViewModel();
|
||||
}
|
||||
|
||||
private void GenerateCaptcha()
|
||||
{
|
||||
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
Random rand = new Random();
|
||||
_activeCaptcha = new string(Enumerable.Repeat(chars, 5)
|
||||
.Select(s => s[rand.Next(s.Length)]).ToArray());
|
||||
|
||||
CaptchaVisual.Text = _activeCaptcha;
|
||||
CaptchaInput.Clear();
|
||||
}
|
||||
|
||||
private void RefreshCaptcha_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GenerateCaptcha();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void LoginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CaptchaInput.Visibility == Visibility.Visible)
|
||||
if (CaptchaInput.Visibility != Visibility.Visible)
|
||||
{
|
||||
Login();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Неверная капча!");
|
||||
GenerateCaptcha();
|
||||
MessageBox.Show("Неверный логин или пароль!");
|
||||
//GenerateCaptcha();
|
||||
}
|
||||
|
||||
if (CaptchaInput.Visibility != Visibility.Visible)
|
||||
@@ -65,12 +54,12 @@ namespace Labaratory
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Неверная капча!");
|
||||
GenerateCaptcha();
|
||||
//GenerateCaptcha();
|
||||
}
|
||||
}
|
||||
private bool Login()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user