[fix bug 976099] Redirect to current page after logging in.

This is too complicated logic and I don't understand why it's needed. You only need to keep lines 90-92.