public void UpdatePassword(int id, [FromBody] PasswordToUpdate password) { if (Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value) != id) { throw new ForbiddenException("Không có quyền chỉnh sửa thông tin người dùng khác"); } _service.UpdatePassword(id, password); }
public void UpdatePassword(int id, PasswordToUpdate password) { var userToUpdate = GetById(id); if(!string.Equals(userToUpdate.Password, EncryptPassword(password.OldPassword))) throw new BadRequestException("Mật khẩu cũ không đúng"); userToUpdate.Password = EncryptPassword(password.NewPassword); _context.SaveChanges(); }