/// <summary>
        /// Perform the method
        /// </summary>
        /// <returns></returns>
        private async Task Login()
        {
            ErrorLabel.Visibility = Visibility.Hidden;
            SetFieldsEnabled(false);
            var credentials = new UsernameCredentials(UsernameField.Text, PasswordField.Password);
            var success     = false;

            try
            {
                success = await session.Authenticate(credentials);
            }
            catch (Session.BadRequestException e)
            {
                logger.LogWarning(e, "Bad login request");
            }
            if (!success)
            {
                ErrorLabel.Visibility = Visibility.Visible;
                ErrorLabel.Focus(); // Makes narrator read the error label
                SetFieldsEnabled(true);
            }
            else
            {
                _ = session.ApplyAllPreferences();
                Close();
            }
        }
        /// <summary>
        /// An async method for actually doing the registration submission
        /// </summary>
        /// <returns></returns>
        private async Task Submit()
        {
            // TODO: show activity indicator
            UpdateValidation();
            SetFieldsEnabled(false);
            var user = new User();

            user.Email = UsernameField.Text;
            var credentials  = new UsernameCredentials(UsernameField.Text, PasswordField.Password);
            var success      = false;
            var errorMessage = "";

            try
            {
                success = await session.RegisterUser(user, credentials, Preferences);
            }
            catch (AuthService.BadPasswordException)
            {
                errorMessage = "Your password is too easily guessed.  Please use another.";
            }
            catch (AuthService.ExistingEmailException)
            {
                errorMessage = "We recognize your email.  Use the 'Already have an account?' link below.";
            }
            catch (AuthService.ExistingUsernameException)
            {
                errorMessage = "We recognize your email.  Use the 'Already have an account?' link below.";
            }
            catch (AuthService.InvalidEmailException)
            {
                errorMessage = "Please provide a valid email address";
            }
            if (success)
            {
                Completed?.Invoke(this, new EventArgs());
            }
            else
            {
                if (errorMessage == "")
                {
                    errorMessage = "We could not complete the request.  Please try again.";
                }
                ErrorLabel.Visibility = Visibility.Visible;
                ErrorLabel.Content    = errorMessage;
                ErrorLabel.Focus(); // Causes screen reader to read label
                SetFieldsEnabled(true);
            }
        }
Exemplo n.º 3
0
        void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar >= 40 && e.KeyChar <= 57)
            {
                //MessageBox.Show("Form.KeyPress: " +
                //e.KeyChar.ToString() + e.KeyChar);

                switch (e.KeyChar)
                {
                case (char)40:
                    openbracket.PerformClick();
                    break;

                case (char)41:
                    closebracket.PerformClick();
                    break;

                case (char)42:
                    mulitply.PerformClick();
                    break;

                case (char)43:
                    plus.PerformClick();
                    break;

                case (char)45:
                    minus.PerformClick();
                    break;

                case (char)46:
                    button_dp.PerformClick();
                    break;

                case (char)47:
                    divide.PerformClick();
                    break;

                case (char)48:
                    button0.PerformClick();
                    break;

                case (char)49:
                    button1.PerformClick();
                    break;

                case (char)50:
                    button2.PerformClick();
                    break;

                case (char)51:
                    button3.PerformClick();
                    break;

                case (char)52:
                    button4.PerformClick();
                    break;

                case (char)53:
                    button5.PerformClick();
                    break;

                case (char)54:
                    button6.PerformClick();
                    break;

                case (char)55:
                    button7.PerformClick();
                    break;

                case (char)56:
                    button8.PerformClick();
                    break;

                case (char)57:
                    button9.PerformClick();
                    break;
                }
            }
            if (e.KeyChar == 8)
            {
                BackSpace.PerformClick();
            }
            if (e.KeyChar == 61 || e.KeyChar == 13)
            {
                answer.PerformClick();
            }
            //if (e.KeyChar == 94)
            //    power.PerformClick();
            //Ctrl C
            //if (e.KeyChar == 3)
            //System.Windows.Forms.Clipboard.SetText(TextResult.Text);
            //ctrl V
            //if (e.KeyChar == 22)
            //{
            //check if paste will be decimal
            //PasteText = System.Windows.Forms.Clipboard.GetText();
            //decimal PasteCheck;
            //if (Decimal.TryParse(PasteText, out PasteCheck))
            //{
            //    TextResult.Text = PasteText;
            //    MemRecall1 = true;
            // }
            //}
            //ctrl X
            //if (e.KeyChar == 24)
            //{
            //  System.Windows.Forms.Clipboard.SetText(TextResult.Text);
            //TextResult.Text = "0";
            // }
            e.Handled = true;
            ErrorLabel.Focus();
        }