public ActionResult ChangePassword(ChangePasswordParams data) { if (Session["username"] != null) { dynamic param = new ExpandoObject(); param.old_psw = data.old_psw; param.new_psw = data.new_psw; param.username = Session["username"].ToString(); param.access_key = Session["key"].ToString(); var client = new HttpClient(); client.BaseAddress = new Uri("http://server-erp2.sma.gov.jm:1786/api/user/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent(JsonConvert.SerializeObject(param), Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("ChangePassword", content).Result; if (response.IsSuccessStatusCode) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK, "password_updated")); } else { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized, "incorrect_password")); } } else { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized, "invalid_session")); } }
public IHttpActionResult ChangePassword([FromBody] ChangePasswordParams changePasswordParams) { try { if (log.IsDebugEnabled) { log.Debug("ChangePassword Call Recevied, parameters:" + changePasswordParams); } return(Ok(_userApplicationService.ChangePassword(new ChangePasswordCommand( HeaderParamUtility.GetApikey(Request), changePasswordParams.OldPassword, changePasswordParams.NewPassword)))); } catch (InvalidOperationException exception) { if (log.IsErrorEnabled) { log.Error("ChangePassword Call Exception ", exception); } return(BadRequest(exception.Message)); } catch (InvalidCredentialException exception) { if (log.IsErrorEnabled) { log.Error("ChangePassword Call Exception ", exception); } return(BadRequest(exception.Message)); } catch (ArgumentNullException exception) { if (log.IsErrorEnabled) { log.Error("ChangePassword Call Exception ", exception); } return(BadRequest(exception.Message)); } catch (Exception exception) { if (log.IsErrorEnabled) { log.Error("ChangePassword Call Exception ", exception); } return(InternalServerError()); } }
public async Task <HttpResponseMessage> ChangePassword(ChangePasswordParams model) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var result = await _userManager.ChangePasswordAsync(Guid.Parse(User.Identity.GetUserId()), model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = await _userManager.FindByIdAsync(Guid.Parse(User.Identity.GetUserId())); if (user != null) { await _signInManager.SignInAsync(user, false, false); } //return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }); return(Request.CreateResponse(HttpStatusCode.OK)); } AddErrors(result); //return View(model); return(Request.CreateResponse(HttpStatusCode.BadRequest)); }