private void OtpTextBox_OnKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter || e.Key == Key.Return)
     {
         Result = OtpTextBox.Text;
         _otpListener.Stop();
         Close();
     }
 }
        private void OtpTextBox_OnKeyDown(object sender, KeyEventArgs e)
        {
            if ((e.Key != Key.Enter && e.Key != Key.Return) || OtpTextBox.Text.Length != 6)
            {
                return;
            }

            Result = OtpTextBox.Text;
            _otpListener.Stop();
            Close();
        }
        public OtpInputDialog()
        {
            InitializeComponent();

            OtpTextBox.Focus();

            _otpListener = new OtpListener();
            _otpListener.OnOtpReceived += otp =>
            {
                Result = otp;
                Dispatcher.Invoke(() =>
                {
                    Close();
                    _otpListener.Stop();
                });
            };

            try
            {
                // Start Listen
                Task.Run(() => _otpListener.Start());
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Could not start OTP HTTP listener.");
            }
        }
        public OtpInputDialog()
        {
            InitializeComponent();

            this.DataContext = new OtpInputDialogViewModel();

            OtpTextBox.Focus();

            if (App.Settings.OtpServerEnabled)
            {
                _otpListener = new OtpListener();
                _otpListener.OnOtpReceived += otp =>
                {
                    Result = otp;
                    Dispatcher.Invoke(() =>
                    {
                        Close();
                        _otpListener?.Stop();
                    });
                };

                try
                {
                    // Start Listen
                    Task.Run(() => _otpListener.Start());
                    Log.Debug("OTP server started...");
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Could not start OTP HTTP listener.");
                }
            }
        }
예제 #5
0
        public void TryAcceptOtp(string otp)
        {
            if (otp.Length != 6)
            {
                Log.Error("Malformed OTP: {Otp}", otp);

                Dispatcher.Invoke(() =>
                {
                    OtpInputPrompt.Text       = ViewModel.OtpInputPromptBadLoc;
                    OtpInputPrompt.Foreground = Brushes.Red;
                    Storyboard myStoryboard   = (Storyboard)OtpInputPrompt.Resources["InvalidShake"];
                    Storyboard.SetTarget(myStoryboard.Children.ElementAt(0), OtpInputPrompt);
                    myStoryboard.Begin();
                    OtpTextBox.Focus();
                });

                return;
            }

            _ignoreCurrentOtp = false;
            OnResult?.Invoke(otp);

            Dispatcher.Invoke(() =>
            {
                if (_ignoreCurrentOtp)
                {
                    Storyboard myStoryboard = (Storyboard)OtpInputPrompt.Resources["InvalidShake"];
                    Storyboard.SetTarget(myStoryboard.Children.ElementAt(0), OtpInputPrompt);
                    myStoryboard.Begin();
                    OtpTextBox.Focus();
                }
                else
                {
                    _otpListener?.Stop();
                    DialogResult = true;
                    Hide();
                }
            });
        }
예제 #6
0
 private void OkButton_OnClick(object sender, RoutedEventArgs e)
 {
     Result = OtpTextBox.Text;
     _otpListener.Stop();
     Close();
 }