Refactor login logic to the login widget.

**DO NOT MERGE**

A little work needs to be done yet.
Maybe it would be good to document the shortcuts that the conditional take in this function... here, or better in the public method.