Bloom.WebLibraryIntegration.BloomParseClient.CreateUser C# (CSharp) Method

CreateUser() public method

public CreateUser ( string account, string password ) : void
account string
password string
return void
        public void CreateUser(string account, string password)
        {
            var request = MakePostRequest("users");
            var metadataJson =
                "{\"username\":\"" + account.ToLowerInvariant() + "\",\"password\":\"" + password + "\",\"email\":\"" + account + "\"}";
            request.AddParameter("application/json", metadataJson, ParameterType.RequestBody);
            var response = Client.Execute(request);
            if (response.StatusCode != HttpStatusCode.Created)
                throw new ApplicationException(response.StatusDescription + " " + response.Content);
        }

Usage Example

Example #1
0
        private void DoSignUp()
        {
            if (!_termsOfUseCheckBox.Checked)
            {
                MessageBox.Show(this,
                                LocalizationManager.GetString("PublishTab.Upload.Login.MustAgreeTerms",
                                                              "In order to sign up for a BloomLibrary.org account, you must check the box indicating that you agree to the BloomLibrary Terms of Use."),
                                LocalizationManager.GetString("PublishTab.Upload.Login.PleaseAgreeTerms", "Please agree to terms of use"),
                                MessageBoxButtons.OK);
                return;
            }
            bool userExists;

            try
            {
                userExists = _client.UserExists(_emailBox.Text);
            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e, LoginOrSignupConnectionFailedString);
                return;
            }
            if (userExists)
            {
                if (
                    MessageBox.Show(this,
                                    LocalizationManager.GetString("PublishTab.Upload.Login.AlreadyHaveAccount", "We cannot sign you up with that address, because we already have an account with that address.  Would you like to log in instead?"),
                                    LocalizationManager.GetString("PublishTab.Upload.Login.AccountAlreadyExists", "Account Already Exists"),
                                    MessageBoxButtons.YesNo)
                    == DialogResult.Yes)
                {
                    RestoreToLogin();
                    return;
                }
            }
            try
            {
                _client.CreateUser(_emailBox.Text, _passwordBox.Text);
                if (_client.LogIn(_emailBox.Text, _passwordBox.Text))
                {
                    Close();
                }
            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e, LoginOrSignupConnectionFailedString);
            }
        }