示例#1
0
        /// <summary>
        /// Create a new account.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ButtonCreateAccount_Clicked(object sender, EventArgs e)
        {
            this.ButtonCreateAccount.IsEnabled = false;
            this.EntryEmail.IsEnabled          = false;
            this.EntryPassword.IsEnabled       = false;
            this.EntryUsername.IsEnabled       = false;
            this.ActivityIndicator.IsVisible   = true;
            this.ActivityIndicator.IsRunning   = true;

            string username = this.EntryUsername.Text.Trim();
            string password = this.EntryPassword.Text.Trim();
            string email    = this.EntryEmail.Text.Trim();

            // Connect to the server in a background task and await a response.
            OperationReturnMessage response = await Task.Run(() => ServerOperations.RegisterAccount(username, password, email));

            if (response != OperationReturnMessage.FalseFailedConnection)
            {
                if (response == OperationReturnMessage.TrueConfirmEmail)
                {
                    this.LabelMessage.Text = "Account successfully created.";
                    this.username          = username;
                    this.password          = password;

                    var confirmationPage = new EmailConfirmationPage(username, password);
                    confirmationPage.EmailConfirmed       += this.OnEmailConfirmed;
                    confirmationPage.ConfirmLaterSelected += this.OnConfirmLaterSelected;
                    await this.Navigation.PushModalAsync(confirmationPage);
                }
                else if (response == OperationReturnMessage.FalseUsernameAlreadyExists)
                {
                    this.LabelMessage.Text = $"Account could not be created - Username already exists.";
                }
                else if (response == OperationReturnMessage.FalseInvalidEmail)
                {
                    this.LabelMessage.Text = $"Account could not be created - Invalid Email.";
                }
                else
                {
                    this.LabelMessage.Text = $"Account could not be created.";
                }
            }
            else
            {
                this.LabelMessage.Text = "Connection failed: Please try again.";
            }

            this.ButtonCreateAccount.IsEnabled = true;
            this.EntryEmail.IsEnabled          = true;
            this.EntryPassword.IsEnabled       = true;
            this.EntryUsername.IsEnabled       = true;
            this.ActivityIndicator.IsVisible   = false;
            this.ActivityIndicator.IsRunning   = false;
        }