Refactor login logic to the login widget.

**DO NOT MERGE**

A little work needs to be done yet.
Shouldn't you stop email at logout rather than change the state?