AuthVM.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using Auth.Models;
  2. using Avalonia.Media;
  3. using Avalonia.Styling;
  4. using ReactiveUI;
  5. using System;
  6. using System.Drawing;
  7. using System.Security.Cryptography.X509Certificates;
  8. using Avalonia.Controls;
  9. using Avalonia.Controls.Shapes;
  10. using System.Linq;
  11. using Avalonia.Threading;
  12. using MsBox.Avalonia.Enums;
  13. using MsBox.Avalonia;
  14. namespace Auth.ViewModels
  15. {
  16. public class AuthVM : ReactiveObject
  17. {
  18. public DispatcherTimer timer = new DispatcherTimer();
  19. public string kod = "";
  20. public string _login = "";
  21. public string _password = "";
  22. public string prov = "";
  23. public string error = "";
  24. public bool ButtonVisible = true;
  25. public bool TextVisible = false;
  26. public bool _Enabled = true;
  27. public string Login
  28. {
  29. get
  30. {
  31. return _login;
  32. }
  33. set
  34. {
  35. this.RaiseAndSetIfChanged(ref _login, value);
  36. }
  37. }
  38. public bool Enabled
  39. {
  40. get
  41. {
  42. return _Enabled;
  43. }
  44. set
  45. {
  46. this.RaiseAndSetIfChanged(ref _Enabled, value);
  47. }
  48. }
  49. public string Password
  50. {
  51. get
  52. {
  53. return _password;
  54. }
  55. set
  56. {
  57. this.RaiseAndSetIfChanged(ref _password, value);
  58. }
  59. }
  60. public bool Visible
  61. {
  62. get
  63. {
  64. return ButtonVisible;
  65. }
  66. set
  67. {
  68. this.RaiseAndSetIfChanged(ref ButtonVisible, value);
  69. }
  70. }
  71. public bool VisibleText
  72. {
  73. get
  74. {
  75. return TextVisible;
  76. }
  77. set
  78. {
  79. this.RaiseAndSetIfChanged(ref TextVisible, value);
  80. }
  81. }
  82. public string Proverka
  83. {
  84. get
  85. {
  86. return prov;
  87. }
  88. set
  89. {
  90. this.RaiseAndSetIfChanged(ref prov, value);
  91. }
  92. }
  93. public async void changeMessage()
  94. {
  95. ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Окно показа сообщения", "Вы ввели неправильные данные", ButtonEnum.Ok).ShowAsync();
  96. }
  97. public async void changeMessage1()
  98. {
  99. ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Окно показа сообщения", "Вы ввели неправильные данные. Попробуйте снова.", ButtonEnum.Ok).ShowAsync();
  100. }
  101. public async void changeMessage2()
  102. {
  103. ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Окно показа сообщения", "Вы ввели неправильные данные. Попробуйте снова через 10 секунд.", ButtonEnum.Ok).ShowAsync();
  104. }
  105. public void timer_tick(object sender, EventArgs e)
  106. {
  107. Enabled = true;
  108. }
  109. private static Random random1 = new Random();
  110. public static string RandomString(int length)
  111. {
  112. const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  113. return new string(Enumerable.Repeat(chars, length)
  114. .Select(s => s[random1.Next(s.Length)]).ToArray());
  115. }
  116. Canvas canva;
  117. public Canvas Canva
  118. {
  119. get => canva;
  120. set => this.RaiseAndSetIfChanged(ref canva, value);
  121. }
  122. public void CreateCaptcha()
  123. {
  124. kod = RandomString(7);
  125. Random rnd = new Random();
  126. SolidColorBrush color = new SolidColorBrush(Avalonia.Media.Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
  127. Canvas canvas = new Canvas()
  128. {
  129. Width = 400,
  130. Height = 400,
  131. Background = color
  132. };
  133. int nach = rnd.Next(0, 100);
  134. foreach (char s in kod)
  135. {
  136. nach = nach + 20 + rnd.Next(20);
  137. if (rnd.Next(2) == 0)
  138. {
  139. TextBlock number = new TextBlock()
  140. {
  141. Text = s.ToString(),
  142. FontSize = 50,
  143. Foreground = Brushes.Black,
  144. Padding = new Avalonia.Thickness(nach, nach + 20 + rnd.Next(20)),
  145. FontWeight = FontWeight.Regular
  146. };
  147. canvas.Children.Add(number);
  148. }
  149. else if (rnd.Next(2) == 1)
  150. {
  151. TextBlock number = new TextBlock()
  152. {
  153. Text = s.ToString(),
  154. FontSize = 50,
  155. Foreground = Brushes.Black,
  156. Padding = new Avalonia.Thickness(nach, nach + 20 + rnd.Next(20)),
  157. FontStyle = FontStyle.Italic
  158. };
  159. canvas.Children.Add(number);
  160. }
  161. else
  162. {
  163. TextBlock number = new TextBlock()
  164. {
  165. Text = s.ToString(),
  166. FontSize = 50,
  167. Foreground = Brushes.Black,
  168. Padding = new Avalonia.Thickness(nach, nach + 20 + rnd.Next(20)),
  169. FontStyle = FontStyle.Italic,
  170. FontWeight = FontWeight.Regular
  171. };
  172. canvas.Children.Add(number);
  173. }
  174. }
  175. for (int i = 0; i < 20; i++)
  176. {
  177. Line line = new Line()
  178. {
  179. StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
  180. EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
  181. 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))),
  182. StrokeThickness = 3
  183. };
  184. canvas.Children.Add(line);
  185. Canva = canvas;
  186. }
  187. }
  188. }
  189. }