Browse Source

Добавлена блокировка кнопки авторизации при провале с капчей

MeseryGG 7 months ago
parent
commit
bbe50dfee1

+ 6 - 4
OOO_WriteAndClear/MVP/Views/AuthorizationUserControl.xaml

@@ -114,10 +114,12 @@
                 </StackPanel>
 
                 <!--Кнопка входа в приложение-->
-                <Button Style="{DynamicResource AuthorizationUserControl.LoginButton}" Grid.Row="5"
-                    Height="60" Margin="0 25 0 0"
-                    Content="Войти"
-                    FontSize="18" Click="LoginButton_Click"/>
+                <Button x:Name="AuthButton"
+                        Style="{DynamicResource AuthorizationUserControl.LoginButton}"
+                        Grid.Row="5"
+                        Height="60" Margin="0 25 0 0"
+                        Content="Войти"
+                        FontSize="18" Click="LoginButton_Click"/>
 
                 <ContentControl Grid.Row="6" 
                             HorizontalAlignment="Center"

+ 20 - 0
OOO_WriteAndClear/MVP/Views/AuthorizationUserControl.xaml.cs

@@ -19,6 +19,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using System.Windows.Threading;
 
 namespace OOO_WriteAndClear.MVP.Views
 {
@@ -32,6 +33,9 @@ namespace OOO_WriteAndClear.MVP.Views
             InitializeComponent();
 
             _presenter = new AuthorizationUserControlPresenter(this);
+            _dispatcherTimer = new DispatcherTimer();
+            _dispatcherTimer.Tick += EnableButton;
+            _dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
         }
 
 
@@ -48,6 +52,8 @@ namespace OOO_WriteAndClear.MVP.Views
                 MessageBoxImage.Error);
             Dispatcher.BeginInvoke(new Action(() =>
             {
+                if (_capchaCode is not null)
+                    DisableButtonAndStartTimer();
                 UpdateCapcha();
                 CapchaStackPanel.Visibility = Visibility.Visible;
             })).Wait();
@@ -76,6 +82,8 @@ namespace OOO_WriteAndClear.MVP.Views
 
         private string? _capchaCode = null;
 
+        private readonly DispatcherTimer _dispatcherTimer;
+
 
         #region Обработчики событий разметки
 
@@ -90,6 +98,7 @@ namespace OOO_WriteAndClear.MVP.Views
             {
                 MessageBox.Show("Капча введена не верно!", "Капча", MessageBoxButton.OK);
                 UpdateCapcha();
+                DisableButtonAndStartTimer();
                 return;
             }
             string login = Login;
@@ -134,5 +143,16 @@ namespace OOO_WriteAndClear.MVP.Views
             }
             CapchaImage.Source = bitmapimage;
         }
+
+        private void DisableButtonAndStartTimer()
+        {
+            AuthButton.IsEnabled = false;
+            _dispatcherTimer.Start();
+        }
+
+        private void EnableButton(object sender, EventArgs e)
+        {
+            AuthButton.IsEnabled = true;
+        }
     }
 }