|
@@ -3,15 +3,17 @@ using Avalonia.Controls;
|
|
|
using Avalonia.Input.Platform;
|
|
|
using Avalonia.Interactivity;
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
+using MsBox.Avalonia;
|
|
|
using System;
|
|
|
using System.IO;
|
|
|
+using LoginGenerator.Models;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
|
|
|
namespace LoginGenerator;
|
|
|
|
|
|
public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
- public static string Path = "D:\\RegistrationAssistant.txt";
|
|
|
-
|
|
|
public Transliteration transliteration = new Transliteration();
|
|
|
public PasswordGenerator passwordGenerator = new PasswordGenerator();
|
|
|
|
|
@@ -31,8 +33,19 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnExisting())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Ïîëüçîâàòåëü ñ òàêèì ëîãèíîì óæå ñóùåñòâóåò");
|
|
|
+ box.ShowAsync();
|
|
|
+ }
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
- File.AppendAllText(Path, $"{FIO.Text} {Login.Text} {Pass.Text} {dateTime.ToShortDateString()}\n");
|
|
|
+ File.AppendAllText(FilePath.PATH, $"{FIO.Text} {Login.Text} {Pass.Text} {dateTime.ToShortDateString()}\n");
|
|
|
}
|
|
|
catch (Exception) { }
|
|
|
}
|
|
@@ -41,6 +54,12 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
|
|
|
string[] parts = FIO.Text.Split(' ');
|
|
|
Clipboard.SetTextAsync(parts[0]);
|
|
@@ -52,6 +71,12 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
|
|
|
string[] parts = FIO.Text.Split(' ');
|
|
|
Clipboard.SetTextAsync(parts[1]);
|
|
@@ -63,6 +88,12 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
|
|
|
string[] parts = FIO.Text.Split(' ');
|
|
|
Clipboard.SetTextAsync(parts[2]);
|
|
@@ -74,6 +105,12 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
|
|
|
string[] parts = FIO.Text.Split(' ');
|
|
|
Clipboard.SetTextAsync(parts[1] + " " + parts[2]);
|
|
@@ -85,6 +122,12 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
Random r = new Random();
|
|
|
string[] parts = FIO.Text.Split(' ');
|
|
|
string newTransliteration = transliteration.Execute(parts[0]) + ".";
|
|
@@ -105,6 +148,18 @@ public partial class GeneratePage : UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ if (string.IsNullOrEmpty(FIO.Text))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
string[] parts = FIO.Text.Split(' ');
|
|
|
Login.Text = transliteration.Execute($"{parts[0]}.{parts[1][0]}{parts[2][0]}");
|
|
|
Pass.Text = passwordGenerator.Execute();
|
|
@@ -114,6 +169,12 @@ public partial class GeneratePage : UserControl
|
|
|
|
|
|
private void RegenPass(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
Pass.Text = passwordGenerator.Execute();
|
|
|
}
|
|
|
|
|
@@ -129,4 +190,52 @@ public partial class GeneratePage : UserControl
|
|
|
IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
|
|
|
Clipboard.SetTextAsync(Pass.Text);
|
|
|
}
|
|
|
+
|
|
|
+ public bool CheckOnExisting()
|
|
|
+ {
|
|
|
+ string[] OneUser;
|
|
|
+ Users u;
|
|
|
+ string[] AllData = File.ReadAllLines(FilePath.PATH);
|
|
|
+ if (AllData.Count() == 0)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ List<Users>? newUsers = new List<Users>();
|
|
|
+ foreach (string user in AllData)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(user))
|
|
|
+ {
|
|
|
+ u = new Users();
|
|
|
+ OneUser = user.Split(' ');
|
|
|
+ u.Surname = OneUser[0].ToString();
|
|
|
+ u.Name = OneUser[1].ToString();
|
|
|
+ u.Patronymic = OneUser[2].ToString();
|
|
|
+ u.Login = OneUser[3].ToString();
|
|
|
+ u.Password = OneUser[4].ToString();
|
|
|
+ u.DateReg = Convert.ToDateTime(OneUser[5]);
|
|
|
+ newUsers.Add(u);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(newUsers.Where(x=>x.Login == Login.Text).First()==null)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool CheckOnSmoothly()
|
|
|
+ {
|
|
|
+ string[] parts = FIO.Text.Split(' ');
|
|
|
+ if (parts.Count() != 3)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|