Esempio n. 1
0
        private async void RegisterNewUserButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            RegisterGroupBox.Enabled    = false;
            AvatarImageGroupBox.Enabled = false;

            AspNetUserModel aspPlayer = new AspNetUserModel();

            if (RegisterPasswordTextBox.Text == ConfirmRegiterPasswordTextBox.Text)
            {
                if (!string.IsNullOrEmpty(RegisterUserEmailTextBox.Text))
                {
                    aspPlayer.Email           = RegisterUserEmailTextBox.Text;
                    aspPlayer.Password        = RegisterPasswordTextBox.Text;
                    aspPlayer.ConfirmPassword = ConfirmRegiterPasswordTextBox.Text;

                    try
                    {
                        string newId = await APIHelper.RegisterNewAspNetUser(aspPlayer);

                        player           = new Player();
                        player.Id        = newId;
                        player.Email     = RegisterUserEmailTextBox.Text;
                        player.FirstName = RegisterFirstNameTextBox.Text;
                        player.LastName  = RegisterLastNameTextBox.Text;
                        player.NickName  = RegisterNickNameTextBox.Text;
                        player.City      = RegisterCityComboBox.Text;

                        player.BlobUri = await GetPlayerImageUri();

                        string token = await APIHelper.Authenticate(RegisterUserEmailTextBox.Text, RegisterPasswordTextBox.Text);

                        success = await APIHelper.InsertNewPlayer(player, token);

                        this.Cursor = Cursors.Default;
                        RegisterGroupBox.Enabled    = true;
                        AvatarImageGroupBox.Enabled = true;

                        if (success)
                        {
                            MessageBox.Show("New player registered successfully!", "Register player success", MessageBoxButtons.OK);
                            this.Close();  // Will trigger PlayerRegisteredEvent
                        }
                        else
                        {
                            MessageBox.Show("New player failed to register! Try again.", "Register player error", MessageBoxButtons.OK);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Something went wrong: " + ex.Message, "Register player error", MessageBoxButtons.OK);
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Esempio n. 2
0
        public static async Task <string> RegisterNewAspNetUser(AspNetUserModel newUser)
        {
            InitializeClient();
            apiHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            using (HttpResponseMessage response = await apiHttpClient.PostAsJsonAsync <AspNetUserModel>("api/account/register", newUser))
            {
                if (response.IsSuccessStatusCode)
                {
                    string token = await Authenticate(newUser.Email, newUser.Password);

                    // get new id for registered user
                    string newId = await GetAspNetUserId(token);

                    return(newId);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }