예제 #1
0
        public async Task <ActionResult <IList <string> > > AddToRole(Guid userId, string role)
        {
            if (!await roleManager.RoleExistsAsync(role))
            {
                throw StatusCodeException.BadRequest();
            }
            var targetUser = await GetUser(userId);

            if (targetUser == null)
            {
                return(NotFound("User not found"));
            }

            var result = await UserManager.AddToRoleAsync(targetUser, role);

            if (result.Succeeded)
            {
                return(Ok(await UserManager.GetRolesAsync(targetUser)));
            }

            return(BadRequest(string.Join(',', result.Errors.Select(e => e.Description))));
        }
        public async Task <RecaptchaResult> Check(string token, string ip)
        {
            var values = new Dictionary <string, string>
            {
                { "secret", options.Value.SecretKey },
                { "response", token },
                { "remoteip", ip }
            };

            var content = new FormUrlEncodedContent(values);

            try
            {
                var response = await httpClient.PostAsync("", content);

                var stringResponse = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <RecaptchaResult>(stringResponse));
            }
            catch (Exception ex)
            {
                throw StatusCodeException.BadRequest(ex.Message);
            }
        }