Refactor login logic to the login widget.

**DO NOT MERGE**

A little work needs to be done yet.
isn't this also a bit of logic that would be good to move to backend? imo frontend should not know about this kind of logic.