public ActionResult Staff_ChangePassword(ChangPasswordModel model, string returnURL) { if (ModelState.IsValid) { string username = model.Username; string password = model.Password; string confirm = model.ConfirmPassword; if (confirm.Equals(password)) { AccountDB accountDB = new AccountDB(); bool check = accountDB.ChangePass(username, password); if (check) { TempData["alertMessage"] = "Success"; return(RedirectToAction("Staff_Product", "Staff")); } else { TempData["alertMessage"] = "Fail"; } } else { ModelState.AddModelError("", "Password must match Confirm"); } } return(View()); }
public IHttpActionResult PostChangePassword([FromBody] ChangPasswordModel model) { if (ModelState.IsValid) { try { this.memberService.ChangePassword(User.Identity.Name, model); return(Ok(new { Message = "Password has chaged" })); }catch (Exception e) { ModelState.AddModelError("Exception", e.Message); } } return(BadRequest(ModelState.GetErrorModelState())); }
public void ChangePassword(string email, ChangPasswordModel model) { try { var memberItem = this.db.Members.SingleOrDefault(item => item.email.Equals(email)); if (memberItem == null) { throw new Exception("Not found member"); } this.db.Members.Attach(memberItem); memberItem.password = PasswordHashModel.Hash(model.new_pass); memberItem.updated = DateTime.Now; this.db.Entry(memberItem).State = System.Data.Entity.EntityState.Modified; this.db.SaveChanges(); }catch (Exception e) { throw e.GetErrorException(); } }