Rework login code

This PR aims to clean up most of the login controller code.

* Move event handlers outside of $scope functions
* Remove $scope.connecting and $scope.connected variables
* Add a setError function