Пример #1
0
        /// <summary>
        ///     Process the enrolling calling the authenticator method, checking the state and displaying appropriate tab
        /// </summary>
        private void ProcessEnroll()
        {
            do
            {
                try
                {
                    var cursor = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;
                    Application.DoEvents();

                    var result = m_steamAuthenticator.Enroll(m_enroll);
                    Cursor.Current = cursor;
                    if (result == false)
                    {
                        if (string.IsNullOrEmpty(m_enroll.Error) == false)
                        {
                            WinAuthForm.ErrorDialog(this, m_enroll.Error);
                        }

                        if (m_enroll.Requires2FA)
                        {
                            WinAuthForm.ErrorDialog(this,
                                                    "It looks like you already have an authenticator added to you account");
                            return;
                        }

                        if (m_enroll.RequiresCaptcha)
                        {
                            using (var web = new WebClient())
                            {
                                var data = web.DownloadData(m_enroll.CaptchaUrl);

                                using (var ms = new MemoryStream(data))
                                {
                                    captchaBox.Image = Image.FromStream(ms);
                                }
                            }

                            loginButton.Enabled   = false;
                            captchaGroup.Visible  = true;
                            captchacodeField.Text = "";
                            captchacodeField.Focus();
                            return;
                        }

                        loginButton.Enabled  = true;
                        captchaGroup.Visible = false;

                        if (m_enroll.RequiresEmailAuth)
                        {
                            if (authoriseTabLabel.Tag == null || string.IsNullOrEmpty((string)authoriseTabLabel.Tag))
                            {
                                authoriseTabLabel.Tag = authoriseTabLabel.Text;
                            }
                            var email = string.IsNullOrEmpty(m_enroll.EmailDomain) == false
                                ? "***@" + m_enroll.EmailDomain
                                : string.Empty;
                            authoriseTabLabel.Text = string.Format((string)authoriseTabLabel.Tag, email);
                            authcodeField.Text     = "";
                            ShowTab("authTab");
                            authcodeField.Focus();
                            return;
                        }

                        if (tabs.TabPages.ContainsKey("authTab"))
                        {
                            tabs.TabPages.RemoveByKey("authTab");
                        }

                        if (m_enroll.RequiresLogin)
                        {
                            ShowTab("loginTab");
                            usernameField.Focus();
                            return;
                        }

                        if (m_enroll.RequiresActivation)
                        {
                            m_enroll.Error = null;

                            Authenticator.AuthenticatorData = m_steamAuthenticator;
                            revocationcodeField.Text        = m_enroll.RevocationCode;

                            ShowTab("confirmTab");

                            activationcodeField.Focus();
                            return;
                        }

                        var error = m_enroll.Error;
                        if (string.IsNullOrEmpty(error))
                        {
                            error = "Unable to add the add the authenticator to your account. Please try again later.";
                        }
                        WinAuthForm.ErrorDialog(this, error);

                        return;
                    }

                    ShowTab("addedTab");

                    revocationcode2Field.Text = m_enroll.RevocationCode;
                    tabs.SelectedTab          = tabs.TabPages["addedTab"];

                    closeButton.Location = cancelButton.Location;
                    closeButton.Visible  = true;
                    cancelButton.Visible = false;

                    break;
                }
                catch (InvalidEnrollResponseException iere)
                {
                    if (WinAuthForm.ErrorDialog(this, "An error occurred while registering the authenticator", iere,
                                                MessageBoxButtons.RetryCancel) != DialogResult.Retry)
                    {
                        break;
                    }
                }
            } while (true);
        }
Пример #2
0
        /// <summary>
        /// Process the enrolling calling the authenticator method, checking the state and displaying appropriate tab
        /// </summary>
        private void ProcessEnroll()
        {
            do
            {
                try
                {
                    var cursor = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;
                    Application.DoEvents();

                    var result = m_steamAuthenticator.Enroll(m_enroll);
                    Cursor.Current = cursor;
                    if (result == false)
                    {
                        if (string.IsNullOrEmpty(m_enroll.Error) == false)
                        {
                            WinAuthForm.ErrorDialog(this, m_enroll.Error, null, MessageBoxButtons.OK);
                        }

                        if (m_enroll.Requires2FA == true)
                        {
                            WinAuthForm.ErrorDialog(this, "这看起来您已经在您的帐户中添加了验证器", null, MessageBoxButtons.OK);
                            return;
                        }

                        if (m_enroll.RequiresCaptcha == true)
                        {
                            using (var web = new WebClient())
                            {
                                byte[] data = web.DownloadData(m_enroll.CaptchaUrl);

                                using (var ms = new MemoryStream(data))
                                {
                                    captchaBox.Image = Image.FromStream(ms);
                                }
                            }
                            loginButton.Enabled   = false;
                            captchaGroup.Visible  = true;
                            captchacodeField.Text = "";
                            captchacodeField.Focus();
                            return;
                        }
                        loginButton.Enabled  = true;
                        captchaGroup.Visible = false;

                        if (m_enroll.RequiresEmailAuth == true)
                        {
                            if (authoriseTabLabel.Tag == null || string.IsNullOrEmpty((string)authoriseTabLabel.Tag) == true)
                            {
                                authoriseTabLabel.Tag = authoriseTabLabel.Text;
                            }
                            string email = string.IsNullOrEmpty(m_enroll.EmailDomain) == false ? "***@" + m_enroll.EmailDomain : string.Empty;
                            authoriseTabLabel.Text = string.Format((string)authoriseTabLabel.Tag, email);
                            authcodeField.Text     = "";
                            ShowTab("authTab");
                            authcodeField.Focus();
                            return;
                        }
                        if (tabs.TabPages.ContainsKey("authTab") == true)
                        {
                            tabs.TabPages.RemoveByKey("authTab");
                        }

                        if (m_enroll.RequiresLogin == true)
                        {
                            ShowTab("loginTab");
                            usernameField.Focus();
                            return;
                        }

                        if (m_enroll.RequiresActivation == true)
                        {
                            m_enroll.Error = null;

                            this.Authenticator.AuthenticatorData = m_steamAuthenticator;
                            revocationcodeField.Text             = m_enroll.RevocationCode;

                            ShowTab("confirmTab");

                            activationcodeField.Focus();
                            return;
                        }

                        string error = m_enroll.Error;
                        if (string.IsNullOrEmpty(error) == true)
                        {
                            error = "无法将添加验证器添加到您的帐户中。请稍后再试。";
                        }
                        WinAuthForm.ErrorDialog(this, error, null, MessageBoxButtons.OK);

                        return;
                    }

                    ShowTab("addedTab");

                    revocationcode2Field.Text = m_enroll.RevocationCode;
                    tabs.SelectedTab          = tabs.TabPages["addedTab"];

                    this.closeButton.Location = this.cancelButton.Location;
                    this.closeButton.Visible  = true;
                    this.cancelButton.Visible = false;

                    break;
                }
                catch (InvalidEnrollResponseException iere)
                {
                    if (WinAuthForm.ErrorDialog(this, "注册验证器时发生错误", iere, MessageBoxButtons.RetryCancel) != System.Windows.Forms.DialogResult.Retry)
                    {
                        break;
                    }
                }
            } while (true);
        }