Skip to content

Instantly share code, notes, and snippets.

@RGkevin
Last active August 29, 2015 13:57
Show Gist options
  • Save RGkevin/9381907 to your computer and use it in GitHub Desktop.
Save RGkevin/9381907 to your computer and use it in GitHub Desktop.
Auth service
'use strict';
angular.module('whiteLabelApp')
.service('Auth', ['Restangular', function (Restangular) {
// AngularJS will instantiate a singleton by calling "new" on this function
var self = this;
self.login = function(data, success, fail, end) {
return Restangular
.all('auth')
.post(data)
.then(function(response) {
if(angular.isFunction(success)) {
success(response);
}
}, function(error) {
if(angular.isFunction(fail)) {
fail(error.data);
}
})
.finally(function() {
if(angular.isFunction(end)) {
end();
}
});
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment