Fixes and refactorings of login logic

* Fixes #131 Login logic needs a redesign
* Fixes #129 Links to scans and issues should be shareable

This is a rather large commit that moves a lot of code. In the process I
also broke invittions but I will file a new bug to deal with that.
Fixes #134 Unbreak invitation handling

Also refactored the code a little to make it less interwoven with the
regular login flow.