Esempio n. 1
0
        public int RegisterUser(Account account)
        {
            Require.NotNull(account, nameof(account));

            var user = new RedmineUser
            {
                Email              = account.Email.Address,
                Login              = GetLoginForLastname(account.Lastname),
                FirstName          = account.Firstname,
                LastName           = account.Lastname,
                Password           = account.Password.Value,
                MustChangePassword = false
            };

            var client              = new HttpClient();
            var address             = _redmineSettings.RedmineHost + "/users.json";
            var authHeaderByteArray = Encoding.ASCII.GetBytes($"{_redmineSettings.ApiKey}:pass");

            client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authHeaderByteArray));
            var response = client.PostAsync(
                address,
                user,
                new XmlMediaTypeFormatter {
                UseXmlSerializer = true
            }).Result;
            var createdUserString = response.Content.ReadAsStringAsync().Result;
            var createdUser       = JObject.Parse(createdUserString);

            return((int)createdUser["user"]["id"]);
        }
Esempio n. 2
0
        public void ChangeUserPassword(Account account, string newPassword)
        {
            Require.NotNull(account, nameof(account));

            var user = new RedmineUser
            {
                Id       = account.RedmineUserId,
                Password = newPassword
            };

            var client              = new HttpClient();
            var address             = _redmineSettings.RedmineHost + $"/users/{account.RedmineUserId}.json";
            var authHeaderByteArray = Encoding.ASCII.GetBytes($"{_redmineSettings.ApiKey}:pass");

            client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authHeaderByteArray));
            client.PutAsync(
                address,
                user,
                new XmlMediaTypeFormatter {
                UseXmlSerializer = true
            });
        }
        public void ChangeUserPassword(Account account, string newPassword)
        {
            Require.NotNull(account, nameof(account));

            var user = new RedmineUser
            {
                Id = account.RedmineUserId,
                Password = newPassword
            };

            var client = new HttpClient();
            var address = _redmineSettings.RedmineHost + $"/users/{account.RedmineUserId}.json";
            var authHeaderByteArray = Encoding.ASCII.GetBytes($"{_redmineSettings.ApiKey}:pass");
            client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authHeaderByteArray));
            client.PutAsync(
                address,
                user,
                new XmlMediaTypeFormatter { UseXmlSerializer = true });
        }
        public int RegisterUser(Account account)
        {
            Require.NotNull(account, nameof(account));

            var user = new RedmineUser
            {
                Email = account.Email.Address,
                Login = GetLoginForLastname(account.Lastname),
                FirstName = account.Firstname,
                LastName = account.Lastname,
                Password = account.Password.Value,
                MustChangePassword = false
            };

            var client = new HttpClient();
            var address = _redmineSettings.RedmineHost + "/users.json";
            var authHeaderByteArray = Encoding.ASCII.GetBytes($"{_redmineSettings.ApiKey}:pass");
            client.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authHeaderByteArray));
            var response = client.PostAsync(
                address,
                user,
                new XmlMediaTypeFormatter {UseXmlSerializer = true}).Result;
            var createdUserString = response.Content.ReadAsStringAsync().Result;
            var createdUser = JObject.Parse(createdUserString);
            return (int)createdUser["user"]["id"];
        }