Improve login controller and add tests for it