Files
meanTorrent/modules/users/client/services/users.client.service.js
Michael Leanos fa138045e6 Deprecated $http success/error promise methods (#1508)
Replaces the $http service calls with promise based methods
of the client-side UsersService for the following:
  Users Change Password
  Users Manage Social Accounts
  Users Password Forgot
  Users Password Reset
  Users Signup
  Users Signin

Modifies tests to reflect changes.

Closes #1479
2016-09-17 12:05:21 -07:00

90 lines
2.2 KiB
JavaScript

(function () {
'use strict';
// Users service used for communicating with the users REST endpoint
angular
.module('users.services')
.factory('UsersService', UsersService);
UsersService.$inject = ['$resource'];
function UsersService($resource) {
var Users = $resource('api/users', {}, {
update: {
method: 'PUT'
},
updatePassword: {
method: 'POST',
url: 'api/users/password'
},
deleteProvider: {
method: 'DELETE',
url: 'api/users/accounts',
params: {
provider: '@provider'
}
},
sendPasswordResetToken: {
method: 'POST',
url: 'api/auth/forgot'
},
resetPasswordWithToken: {
method: 'POST',
url: 'api/auth/reset/:token'
},
signup: {
method: 'POST',
url: 'api/auth/signup'
},
signin: {
method: 'POST',
url: 'api/auth/signin'
}
});
angular.extend(Users, {
changePassword: function (passwordDetails) {
return this.updatePassword(passwordDetails).$promise;
},
removeSocialAccount: function (provider) {
return this.deleteProvider({
provider: provider // api expects provider as a querystring parameter
}).$promise;
},
requestPasswordReset: function (credentials) {
return this.sendPasswordResetToken(credentials).$promise;
},
resetPassword: function (token, passwordDetails) {
return this.resetPasswordWithToken({
token: token // api expects token as a parameter (i.e. /:token)
}, passwordDetails).$promise;
},
userSignup: function (credentials) {
return this.signup(credentials).$promise;
},
userSignin: function (credentials) {
return this.signin(credentials).$promise;
}
});
return Users;
}
// TODO this should be Users service
angular
.module('users.admin.services')
.factory('AdminService', AdminService);
AdminService.$inject = ['$resource'];
function AdminService($resource) {
return $resource('api/users/:userId', {
userId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
}());