Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #386 from esune/em-836
Browse files Browse the repository at this point in the history
EM-836: Use native Promises to fix broken login in Angular 1.6+
  • Loading branch information
Randy P authored Apr 19, 2018
2 parents 13ac322 + 71d8c27 commit 834375a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
11 changes: 6 additions & 5 deletions modules/core/client/services/core.access.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ angular.module('core')
reload: function (currentUser, force) {
return new Promise(function (resolve, reject) {
if ($window.application.user !== currentUser || force === true) {
$http.get('api/application').success(function (response) {
$window.application.userCan = response.userCan;
$http.get('api/application').then(function (response) {
$window.application.userCan = response.data.userCan;
$window.application._id = 'application';
$window.application.user = currentUser;
resolve(response.userCan);
})
.error(reject);
resolve(response.data.userCan);
}, function(){
reject();
});
}
else {
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ function controllerAuthentication($scope, $state, $http, $location, $window, Aut
return false;
}

$http.post('/api/auth/signup', loginPanel.credentials).success(function (response) {
$http.post('/api/auth/signup', loginPanel.credentials).then(function (response) {
// If successful we assign the response to the global user model
loginPanel.authentication.user = response;
loginPanel.authentication.user = response.data;
// And redirect to the previous or home page
$state.go($state.previous.state.name || 'projects', $state.previous.params);
}).error(function (response) {
loginPanel.error = response.message;
}, function (response) {
loginPanel.error = response.data.message;
});
};

Expand All @@ -49,13 +49,13 @@ function controllerAuthentication($scope, $state, $http, $location, $window, Aut

return false;
}
$http.post('/api/auth/signin', loginPanel.credentials).success(function (response) {
$http.post('/api/auth/signin', loginPanel.credentials).then(function (response) {
// If successful we assign the response to the global user model
loginPanel.authentication.user = response;
loginPanel.authentication.user = response.data;
// And redirect to the previous or home page
$state.go('projects');
}).error(function (response) {
loginPanel.error = response.message;
}, function (response) {
loginPanel.error = response.data.message;
});
};

Expand Down
16 changes: 8 additions & 8 deletions modules/users/client/controllers/password.client.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
$scope.askForPasswordReset = function () {
$scope.success = $scope.error = null;

$http.post('/api/auth/forgot', $scope.credentials).success(function (response) {
$http.post('/api/auth/forgot', $scope.credentials).then(function (response) {
// Show user success message and clear form
$scope.credentials = null;
$scope.success = response.message;
$scope.success = response.data.message;

}).error(function (response) {
}, function (response) {
// Show user error message and clear form
$scope.credentials = null;
$scope.error = response.message;
$scope.error = response.data.message;
});
};

// Change user password
$scope.resetUserPassword = function () {
$scope.success = $scope.error = null;

$http.post('/api/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function (response) {
$http.post('/api/auth/reset/' + $stateParams.token, $scope.passwordDetails).then(function (response) {
// If successful show success message and clear form
$scope.passwordDetails = null;

// Attach user profile
Authentication.user = response;
Authentication.user = response.data;

// And redirect to the index page
$location.path('/password/reset/success');
}).error(function (response) {
$scope.error = response.message;
}, function (response) {
$scope.error = response.data.message;
});
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ angular.module('users').controller('ChangePasswordController', ['$scope', '$http
return false;
}

$http.post('/api/users/password', $scope.passwordDetails).success(function (/* response */) {
$http.post('/api/users/password', $scope.passwordDetails).then(function (/* response */) {
// If successful show success message and clear form
$scope.$broadcast('show-errors-reset', 'passwordForm');
$scope.success = true;
$scope.passwordDetails = null;
}).error(function (response) {
$scope.error = response.message;
}, function (response) {
$scope.error = response.data.message;
});
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ angular.module('users').controller('SocialAccountsController', ['$scope', '$http
params: {
provider: provider
}
}).success(function (response) {
}).then(function (response) {
// If successful show success message and clear form
$scope.success = true;
$scope.user = Authentication.user = response;
}).error(function (response) {
$scope.error = response.message;
$scope.user = Authentication.user = response.data;
}, function (response) {
$scope.error = response.data.message;
});
};
}
Expand Down

0 comments on commit 834375a

Please sign in to comment.