123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- using Auth.Models;
- using Avalonia.Media;
- using Avalonia.Styling;
- using ReactiveUI;
- using System;
- using System.Drawing;
- using System.Security.Cryptography.X509Certificates;
- using Avalonia.Controls;
- using Avalonia.Controls.Shapes;
- using System.Linq;
- using Avalonia.Threading;
- using MsBox.Avalonia.Enums;
- using MsBox.Avalonia;
- namespace Auth.ViewModels
- {
- public class AuthVM : ReactiveObject
- {
- public DispatcherTimer timer = new DispatcherTimer();
- public string kod = "";
- public string _login = "";
- public string _password = "";
- public string prov = "";
- public string error = "";
- public bool ButtonVisible = true;
- public bool TextVisible = false;
- public bool _Enabled = true;
- public string Login
- {
- get
- {
- return _login;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref _login, value);
- }
- }
- public bool Enabled
- {
- get
- {
- return _Enabled;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref _Enabled, value);
- }
- }
- public string Password
- {
- get
- {
- return _password;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref _password, value);
- }
- }
- public bool Visible
- {
- get
- {
- return ButtonVisible;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref ButtonVisible, value);
- }
- }
- public bool VisibleText
- {
- get
- {
- return TextVisible;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref TextVisible, value);
- }
- }
- public string Proverka
- {
- get
- {
- return prov;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref prov, value);
- }
- }
- public async void changeMessage()
- {
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Окно показа сообщения", "Вы ввели неправильные данные", ButtonEnum.Ok).ShowAsync();
- }
- public async void changeMessage1()
- {
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Окно показа сообщения", "Вы ввели неправильные данные. Попробуйте снова.", ButtonEnum.Ok).ShowAsync();
- }
- public async void changeMessage2()
- {
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Окно показа сообщения", "Вы ввели неправильные данные. Попробуйте снова через 10 секунд.", ButtonEnum.Ok).ShowAsync();
- }
- public void timer_tick(object sender, EventArgs e)
- {
- Enabled = true;
- }
- private static Random random1 = new Random();
- public static string RandomString(int length)
- {
- const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- return new string(Enumerable.Repeat(chars, length)
- .Select(s => s[random1.Next(s.Length)]).ToArray());
- }
- Canvas canva;
- public Canvas Canva
- {
- get => canva;
- set => this.RaiseAndSetIfChanged(ref canva, value);
- }
- public void CreateCaptcha()
- {
- kod = RandomString(7);
- Random rnd = new Random();
- SolidColorBrush color = new SolidColorBrush(Avalonia.Media.Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
- Canvas canvas = new Canvas()
- {
- Width = 400,
- Height = 400,
- Background = color
- };
- int nach = rnd.Next(0, 100);
- foreach (char s in kod)
- {
- nach = nach + 20 + rnd.Next(20);
- if (rnd.Next(2) == 0)
- {
- TextBlock number = new TextBlock()
- {
- Text = s.ToString(),
- FontSize = 50,
- Foreground = Brushes.Black,
- Padding = new Avalonia.Thickness(nach, nach + 20 + rnd.Next(20)),
- FontWeight = FontWeight.Regular
- };
- canvas.Children.Add(number);
- }
- else if (rnd.Next(2) == 1)
- {
- TextBlock number = new TextBlock()
- {
- Text = s.ToString(),
- FontSize = 50,
- Foreground = Brushes.Black,
- Padding = new Avalonia.Thickness(nach, nach + 20 + rnd.Next(20)),
- FontStyle = FontStyle.Italic
- };
- canvas.Children.Add(number);
- }
- else
- {
- TextBlock number = new TextBlock()
- {
- Text = s.ToString(),
- FontSize = 50,
- Foreground = Brushes.Black,
- Padding = new Avalonia.Thickness(nach, nach + 20 + rnd.Next(20)),
- FontStyle = FontStyle.Italic,
- FontWeight = FontWeight.Regular
- };
- canvas.Children.Add(number);
- }
- }
- for (int i = 0; i < 20; i++)
- {
- Line line = new Line()
- {
- StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
- EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
- Stroke = new SolidColorBrush(Avalonia.Media.Color.FromRgb(Convert.ToByte(rnd.Next(250) + 3), Convert.ToByte(rnd.Next(250) + 3), Convert.ToByte(rnd.Next(250) + 3))),
- StrokeThickness = 3
- };
- canvas.Children.Add(line);
- Canva = canvas;
- }
- }
- }
- }
|