Refactor login logic to the login widget.

**DO NOT MERGE**

A little work needs to be done yet.
in line with the comment above, I would separate all the writes to global state so they are easier to detach in the next steps.