Theory of Spin Excitations in Undoped and Underdoped Cuprates