         password = @.form.password
 
         @.loading = true
-
-        onSuccess = (user) =>
-            @.$gmAuth.setUser(user)
-
-            if @.$routeParams['next'] and @.$routeParams['next'] != '/login'
-                @.$location.url($routeParams['next'])
-            else
-                @.$location.url("/")
-
-        onError = (data) =>
-            @.error = true
-            @.errorMessage = data.detail
-
-        promise = @.rs.login(username, password)
-        promise.then(onSuccess, onError).then =>
-            @.loading = false
-
+        @.rs.login(username, password)
+            .then(_.bind(@.onSuccess, @), _.bind(@.onError, @))
+            .then(=> @.loading = false)
+
+    onError: (data) ->
+        @.error = true
+        @.errorMessage = data.detail
+
+    onSuccess: (user) ->
+        @.gmAuth.setUser(user)
+        if @.routeParams['next'] and @.routeParams['next'] != '/login'
+            @.location.url(@.routeParams['next'])
+        else
+            @.location.url("/")
 
 RecoveryController = ($scope, $rootScope, $location, rs, $i18next) ->
     $rootScope.pageTitle = $i18next.t('login.password-recovery-title')

# limitations under the License.

class LoginController extends TaigaBaseController
    constructor: (@$scope, @$rootScope, @$location, @$routeParams, @rs, @$gmAuth, @$i18next, @$favico) ->
        $favico.reset()
        $rootScope.pageTitle = $i18next.t('login.login-title')
        $rootScope.pageSection = 'login'
        @.form = {}

    submit: ->

    return

module = angular.module("taiga.controllers.auth", [])
module.controller("LoginController", LoginController)
module.controller("RecoveryController", ['$scope', '$rootScope', '$location', 'resource', '$i18next',
                                         RecoveryController])
module.controller("ChangePasswordController", ['$scope', '$rootScope', '$location', '$routeParams', 'resource',
