mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-01 00:18:19 +02:00
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
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
.module('users')
|
||||
.controller('AuthenticationController', AuthenticationController);
|
||||
|
||||
AuthenticationController.$inject = ['$scope', '$state', '$http', '$location', '$window', 'Authentication', 'PasswordValidator'];
|
||||
AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', 'Authentication', 'PasswordValidator'];
|
||||
|
||||
function AuthenticationController($scope, $state, $http, $location, $window, Authentication, PasswordValidator) {
|
||||
function AuthenticationController($scope, $state, UsersService, $location, $window, Authentication, PasswordValidator) {
|
||||
var vm = this;
|
||||
|
||||
vm.authentication = Authentication;
|
||||
@@ -33,15 +33,9 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
$http.post('/api/auth/signup', vm.credentials).success(function (response) {
|
||||
// If successful we assign the response to the global user model
|
||||
vm.authentication.user = response;
|
||||
|
||||
// And redirect to the previous or home page
|
||||
$state.go($state.previous.state.name || 'home', $state.previous.params);
|
||||
}).error(function (response) {
|
||||
vm.error = response.message;
|
||||
});
|
||||
UsersService.userSignup(vm.credentials)
|
||||
.then(onUserSignupSuccess)
|
||||
.catch(onUserSignupError);
|
||||
}
|
||||
|
||||
function signin(isValid) {
|
||||
@@ -53,15 +47,9 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
$http.post('/api/auth/signin', vm.credentials).success(function (response) {
|
||||
// If successful we assign the response to the global user model
|
||||
vm.authentication.user = response;
|
||||
|
||||
// And redirect to the previous or home page
|
||||
$state.go($state.previous.state.name || 'home', $state.previous.params);
|
||||
}).error(function (response) {
|
||||
vm.error = response.message;
|
||||
});
|
||||
UsersService.userSignin(vm.credentials)
|
||||
.then(onUserSigninSuccess)
|
||||
.catch(onUserSigninError);
|
||||
}
|
||||
|
||||
// OAuth provider request
|
||||
@@ -73,5 +61,31 @@
|
||||
// Effectively call OAuth authentication route:
|
||||
$window.location.href = url;
|
||||
}
|
||||
|
||||
// Authentication Callbacks
|
||||
|
||||
function onUserSignupSuccess(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
vm.authentication.user = response;
|
||||
|
||||
// And redirect to the previous or home page
|
||||
$state.go($state.previous.state.name || 'home', $state.previous.params);
|
||||
}
|
||||
|
||||
function onUserSignupError(response) {
|
||||
vm.error = response.data.message;
|
||||
}
|
||||
|
||||
function onUserSigninSuccess(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
vm.authentication.user = response;
|
||||
|
||||
// And redirect to the previous or home page
|
||||
$state.go($state.previous.state.name || 'home', $state.previous.params);
|
||||
}
|
||||
|
||||
function onUserSigninError(response) {
|
||||
vm.error = response.data.message;
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user