|
@@ -0,0 +1,315 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using ReactiveUI;
|
|
|
+using Avalonia;
|
|
|
+using Avalonia.Controls;
|
|
|
+using Avalonia.Input.Platform;
|
|
|
+using Avalonia.Interactivity;
|
|
|
+using Avalonia.Markup.Xaml;
|
|
|
+using MsBox.Avalonia;
|
|
|
+using System.Windows;
|
|
|
+using System.Text;
|
|
|
+using System.IO;
|
|
|
+using LoginGenerator.Models;
|
|
|
+using System.Linq;
|
|
|
+using System.Drawing.Imaging;
|
|
|
+using Avalonia.Input;
|
|
|
+using Avalonia.Media;
|
|
|
+using System.Drawing;
|
|
|
+
|
|
|
+namespace LoginGenerator.ViewModels
|
|
|
+{
|
|
|
+ public class GeneratePageViewModel : ReactiveObject
|
|
|
+ {
|
|
|
+
|
|
|
+ public Transliteration transliteration = new Transliteration();
|
|
|
+ public PasswordGenerator passwordGenerator = new PasswordGenerator();
|
|
|
+
|
|
|
+ private SolidColorBrush background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(255, 255, 255));
|
|
|
+
|
|
|
+ public SolidColorBrush MyProperty
|
|
|
+ {
|
|
|
+ get => background;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref background, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private string? fio;
|
|
|
+ public string? FIO
|
|
|
+ {
|
|
|
+ get => fio;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref fio, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private string? login;
|
|
|
+ public string? Login
|
|
|
+ {
|
|
|
+ get => login;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref login, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private string? pass;
|
|
|
+ public string? Pass
|
|
|
+ {
|
|
|
+ get => pass;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref pass, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void CopyAll_Click()
|
|
|
+ {
|
|
|
+ ClipboardService.SetText($"{FIO}\n{Login}\n{Pass}");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void WriteIn()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnExisting())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Ïîëüçîâàòåëü ñ òàêèì ëîãèíîì óæå ñóùåñòâóåò");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DateTime dateTime = DateTime.Now;
|
|
|
+ File.AppendAllText(FilePath.PATH, $"{FIO} {Login} {Pass} {dateTime.ToShortDateString()}\n");
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OSurnameCopy_Click()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ ClipboardService.SetText(parts[0]);
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ONameCopy_Click()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ ClipboardService.SetText(parts[1]);
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OPatronymicCopy_Click()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ ClipboardService.SetText(parts[2]);
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ONamePatronymicCopy_Click()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ ClipboardService.SetText(parts[1] + " " + parts[2]);
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void TMore_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Random r = new Random();
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ string newTransliteration = transliteration.Execute(parts[0]) + ".";
|
|
|
+ for (int i = 0; i < r.Next(5); i++)
|
|
|
+ {
|
|
|
+ newTransliteration += transliteration.Execute(parts[1][i].ToString());
|
|
|
+ }
|
|
|
+ for (int i = 0; i < r.Next(1, 5); i++)
|
|
|
+ {
|
|
|
+ newTransliteration += transliteration.Execute(parts[2][i].ToString());
|
|
|
+ }
|
|
|
+ Login = newTransliteration;
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void GenerateAll()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ Login = transliteration.Execute($"{parts[0]}.{parts[1][0]}{parts[2][0]}");
|
|
|
+ Pass = passwordGenerator.Execute();
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RegenPass()
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(FIO))
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!CheckOnSmoothly())
|
|
|
+ {
|
|
|
+ var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
|
|
|
+ box.ShowAsync();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Pass = passwordGenerator.Execute();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void LoginCopy()
|
|
|
+ {
|
|
|
+ ClipboardService.SetText(Login);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PassCopy()
|
|
|
+ {
|
|
|
+ ClipboardService.SetText(Pass);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Users? maybeNew = newUsers.Where(x => x.Login == Login).FirstOrDefault();
|
|
|
+ if (maybeNew == null)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool CheckOnSmoothly()
|
|
|
+ {
|
|
|
+ string[] parts = FIO.Split(' ');
|
|
|
+ if (parts.Count() != 3)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SwitchTheme()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|