public async Task <ApiResult <bool> > ChangeUserPassword(AppUserChangePasswordDTO appUserChangePassword) { try { var user = await _userManager.FindByIdAsync(appUserChangePassword.Id); if (user == null) { throw new EShopException(ResponseMessage.GetDataFailed); } var changePass = await _userManager.ChangePasswordAsync(user, appUserChangePassword.OldPasswordHash, appUserChangePassword.PasswordHash); if (changePass.Succeeded) { //return true; return(new ApiSuccessResult <bool>()); } string.Join(", ", changePass.Errors.Select(x => x.Description)); //return false; return(new ApiErrorResult <bool>($"Error:{string.Join(", ", changePass.Errors.Select(x => x.Description))}")); } catch (Exception ex) { _logger.LogError(ex, "{0} {1}", "Something went wrong in ", nameof(ChangeUserPassword)); throw; } }
public async Task <ApiResult <bool> > ChangeUserPassword(AppUserChangePasswordDTO appUserChangePassword) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); //lấy token var json = JsonConvert.SerializeObject(appUserChangePassword); //convert json to string var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PutAsync($"/api/users", httpContent); var result = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode)//kiểm tra status code { return(JsonConvert.DeserializeObject <ApiSuccessResult <bool> >(result)); } return(JsonConvert.DeserializeObject <ApiErrorResult <bool> >(result)); }
public async Task <IActionResult> ChangeUserPassword(AppUserChangePasswordDTO appUserChangePassword) { return(Ok(await _userService.ChangeUserPassword(appUserChangePassword))); }