コード例 #1
0
        /// <summary>
        /// Changes the profile passphrase
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="newPassphrase"></param>
        /// <returns></returns>
        public static async Task ChangePassphraseAsync(string oldPassphrase, string newPassphrase)
        {
            using (var client = new HttpClient())
            {
                // Authorize the request.
                await AuthorizeRequest(client);
                // Add passphrase to message
                AddPassphraseHeader(client, oldPassphrase);

                // Create object to send to API
                var values = new
                {
                    NewPassphrase = newPassphrase
                };

                // Create JSON content.
                var content = JsonContent(values);

                // Create
                var response = await client.PostAsync(GetUrl($"api/profiles/{CurrentProfile.Id}/change-passphrase"), content);

                // Deserialize the object based on the result
                if (response.IsSuccessStatusCode)
                {
                    // Store the new passphrase
                    Passphrase = newPassphrase;
                }
                else
                {
                    throw await CreateException(response);
                }
            }

        }
コード例 #2
0
        /// <summary>
        /// Creates an account in the system
        /// </summary>
        /// <param name="username"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public static async Task<SuccessResponse> CreateAccountAsync(string username, string password, string confirmPassword)
        {
            using (var client = new HttpClient())
            {
                //create object to pass
                var values = new
                {
                    email = username,
                    password = password,
                    confirmPassword = confirmPassword
                };

                //create content
                var content = JsonContent(values);

                //execute request
                var response = await client.PostAsync(GetUrl("api/account/register"), content);

                //check if the response is a success code
                if (response.IsSuccessStatusCode)
                {
                    //get the response content
                    var data = await response.Content.ReadAsStringAsync();

                    return new SuccessResponse();
                }
                else
                {
                    throw await CreateException(response);
                }
            }

        }