123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using Avalonia.Controls;
- using ReactiveUI;
- using System.Threading;
- namespace Captchapp.ViewModels
- {
- public class MainWindowViewModel : ViewModelBase
- {
- UserControl control = new Page1();
- public UserControl Control {
- get => control;
- set => this.RaiseAndSetIfChanged(ref control, value);
- }
- Page1ViewModel page1VM = new Page1ViewModel();
- Page2ViewModel page2VM = new Page2ViewModel();
- public Page1ViewModel Page1VM {
- get => page1VM;
- set => page1VM = value;
- }
- public Page2ViewModel Page2VM
- {
- get => page2VM;
- set => page2VM = value;
- }
- public void toPage1()
- {
- Control = new Page1();
- }
- public void toPage2()
- {
- if (Page1VM.Authorize())
- {
- Control = new Page2();
- Page1VM.ErrorMessage = "";
- Page1VM.ErrorVisibility = false;
- }
- else
- {
- Page1VM.ErrorMessage = "Логин или пароль неправильные. Повторите попытку";
- Page1VM.ErrorVisibility = true;
- Page1VM.makeCaptcha();
- Page1VM.LoginVisibility = false;
- }
-
- }
- private Timer timer;
- private int count = 0;
- public void toPage2Captcha()
- {
- if (Page1VM.checkCaptcha())
- {
- Page1VM.ErrorVisibility = false;
- Page1VM.LoginVisibility = true;
- Page1VM.CaptchaVisibility = false;
- Control = new Page2();
- Page1VM.ErrorMessage = "";
- }
- else
- {
- Page1VM.ErrorMessage = "Логин или пароль неправильные. Повторите попытку";
- Page1VM.ErrorVisibility = true;
- Page1VM.makeCaptcha();
- Page1VM.CaptchaVisibility = false;
- Page1VM.LoginVisibility = false;
- // Здесь вызывается таймер
- Page1VM.TimerVisibility = true;
- Page1VM.TextBoxEnable = false;
- Page1VM.Password = "";
- Page1VM.Email = "";
- timer = new Timer(timerText, null, 0,1000);
- }
- }
- public void timerText(object? obj)
- {
- count++;
- Page1VM.TimerMessage = $"Попробуйте снова через {10-count} секунд";
- if (count >= 10) {
- Page1VM.TimerVisibility = false;
- Page1VM.TextBoxEnable = true;
- Page1VM.CaptchaVisibility = true;
- count = 0;
- timer.Dispose();
- }
- }
- }
-
- }
|