Esempio n. 1
0
 /// <summary>
 /// Call the HTTP query event handler in UI context.
 /// </summary>
 private void FireOnHttpEvent(HttpQueryEventArgs ev)
 {
     Base.ExecInUI(new Base.EmptyDelegate(delegate()
     {
         if (OnHttpQueryEvent != null)
         {
             OnHttpQueryEvent(this, ev);
         }
     }), null);
 }
Esempio n. 2
0
 /// <summary>
 /// Call the HTTP query event handler in UI context.
 /// </summary>
 private void FireOnHttpEvent(HttpQueryEventArgs ev)
 {
     Base.ExecInUI(new Base.EmptyDelegate(delegate()
     {
         if (OnHttpQueryEvent != null) OnHttpQueryEvent(this, ev);
     }), null);
 }
Esempio n. 3
0
        // TODO: refactor callback to be re-useable.
        private void HandleHttpQueryResult(Object sender, HttpQueryEventArgs args)
        {
            try
            {
                string errTmpl = "We were unable to complete your sign-up: {0}. Please try again later or contact your network administrator.";

                this.Enabled = true;

                // Bailout if required.
                if (m_httpQuery == null) return;

                if (args.Type == HttpQueryEventType.Done)
                {
                    // Query succeeded, auto-signin with obtained credentials.
                    if (m_httpQuery.Result == "ok")
                    {
                        ((ConfigKPPWizard)GetWizard()).ShowSignInPage(true, false);
                        return;
                    }
                    // Email has not been confirmed yet.
                    else if (m_httpQuery.Result == "confirm")
                    {
                        Misc.KwmTellUser("Your email address has not been confirmed yet. " +
                                         "Please click on the link present in your confirmation email. " +
                                         "If you did not receive the confirmation email, look at your spam folder.",
                                         MessageBoxIcon.Information);
                    }

                    else
                    {
                        throw new Exception("Unexpected server error: " + m_httpQuery.Result + Environment.NewLine + Environment.NewLine +
                                            "Please report this to [email protected].");
                    }
                }

                else if (args.Type == HttpQueryEventType.DnsError)
                {
                    Misc.KwmTellUser(String.Format(errTmpl, "Sign-up failed", args.Ex.Message));
                }

                else if (args.Type == HttpQueryEventType.HttpError)
                {
                    string errMsg = "";
                    if (string.IsNullOrEmpty(m_httpQuery.Result))
                        if (args.Ex != null)
                            errMsg = args.Ex.Message;
                        else
                            errMsg = "unknown server error.";
                    else
                        errMsg = m_httpQuery.Result;

                    Misc.KwmTellUser(String.Format(errTmpl, errMsg), "Sign-up failed", MessageBoxIcon.Error);
                }
            }

            catch (Exception ex)
            {
                Base.HandleException(ex);
            }
            finally
            {
                CancelCtx();
            }
        }
Esempio n. 4
0
        // FIXME refactor with ConfigKPPEmailVerif.
        private void HandleHttpQueryResult(Object sender, HttpQueryEventArgs args)
        {
            try
            {
                string errTmpl = "We were unable to complete your sign-up: {0}. Please try again later or contact your network administrator.";

                this.Enabled = true;

                // Bailout if required.
                if (m_httpQuery == null) return;

                if (args.Type == HttpQueryEventType.Done)
                {
                    ((ConfigKPPWizard)GetWizard()).SetSignInCredentials(creds.KpsAddress, creds.UserName, creds.Password);
                    if (m_httpQuery.Result == "ok")
                    {
                        ((ConfigKPPWizard)GetWizard()).ShowSignInPage(true, false);
                        return;
                    }

                    else if (m_httpQuery.Result == "confirm")
                    {
                        ((ConfigKPPWizard)GetWizard()).ShowEmailVerificationPage();
                        return;
                    }

                    else
                    {
                        throw new Exception("Unexpected server error: " + m_httpQuery.Result + Environment.NewLine + Environment.NewLine +
                                            "Please report this to [email protected].");
                    }
                }

                else if (args.Type == HttpQueryEventType.DnsError)
                {
                    Misc.KwmTellUser(String.Format(errTmpl, "Sign-up failed", args.Ex.Message));
                }

                else if (args.Type == HttpQueryEventType.HttpError)
                {
                    string errMsg = "";

                    if (m_httpQuery.StatusCode == HttpStatusCode.Forbidden)
                    {
                        // When the web services responds with a 403, the response body is not an error string to display to the user,
                        // instead, it's a protocol response that can be safely used here for exact match, to indicate the reason of faliure of the registration process.
                        switch (m_httpQuery.Result)
                        {
                            case "registration_disabled":
                                Misc.KwmTellUser("Free registration is currently closed. Please try again later.", "Registration is closed", MessageBoxIcon.Information);
                                break;
                            case "user_login_taken":
                                Misc.KwmTellUser("The email address you entered is not available. Please pick another one.", "Registration incomplete", MessageBoxIcon.Information);
                                break;
                            case "user_registration_locked":
                                Misc.KwmTellUser("The email address you entered is not available. Please pick another one.", "Registration incomplete", MessageBoxIcon.Information);
                                break;
                            default:
                                Misc.KwmTellUser(String.Format(errTmpl, "protocol error."), "Sign-up failed", MessageBoxIcon.Error);
                                break;
                        }

                    }
                    else
                    {
                        if (string.IsNullOrEmpty(m_httpQuery.Result))
                            if (args.Ex != null)
                                errMsg = args.Ex.Message;
                            else
                                errMsg = "unknown server error";
                        else
                                errMsg = m_httpQuery.Result;

                        Misc.KwmTellUser(String.Format(errTmpl, errMsg), "Sign-up failed", MessageBoxIcon.Error);
                    }
                }
            }

            catch (Exception ex)
            {
                Base.HandleException(ex);
            }
            finally
            {
                CancelCtx();
            }
        }