How an unpopular president and an unpopular war provided an opening for Democrats to make sweeping gains in the midterms.