Modified ssl certificate authentication to handle next redirection

Makes small changes in lms and cms both so that user's go to the
original page they intended to if they weren't already logged in.

Building this also exposed an infinite redirect loop on logout when SSL
auth is enabled, so that was also fixed with tests in another commit.

Heads up to @sarina @pdpinch and @ichuang

Potential reviewers: @brianhw and @jbau