public async Task <ResBase> ChangePassword(string username, IMUser.ChangePassword input) { // get user var tbuUser = await _repoUser.GetOne(username); if (tbuUser == null) { return(new ResBase($"user {username} not found")); } // validate user's old password if (!_utlPasswordHasher.ValidatePassword(input.oldPassword, tbuUser.password)) { return(new ResBase($"old password is incorrect")); } // edit header tbuUser.password = _utlPasswordHasher.HashPassword(input.newPassword); tbuUser.md_password = now; try { // update user _repoUser.Update(tbuUser); // commit await _unitOfWork.Commit(); return(new ResBase()); } catch (Exception ex) { return(new ResBase($"Server errror: {ex.Message}")); } }
public async Task <IActionResult> ChangePassword([FromBody] IMUser.ChangePassword input) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var res = await _svsUser.ChangePassword(User.Identity.Name, input); if (!res._rs) { return(BadRequest(res._rt)); } return(Ok(res._rt)); }