我正在尝试使用此服务模块注册新用户(注册):
(function () {
angular.module('starter')
.service('ProfileModel', function ($http, Backand) {
var service = this,
baseUrl = '/1/objects/',
objectName = 'users/';
function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}
function getUrlForId(id) {
return getUrl() + id;
}
service.all = function () {
return $http.get(getUrl());
};
service.fetch = function (id) {
return $http.get(getUrlForId(id));
};
service.create = function (object) {
return $http.post(getUrl(), object);
};
service.update = function (id, object) {
return $http.put(getUrlForId(id), object);
};
service.delete = function (id) {
return $http.delete(getUrlForId(id));
};
service.currentUser = {};
loadUserDetails();
function loadUserDetails() {
return Backand.getUserDetails()
.then(function (data) {
service.currentUser.details = data;
if(data !== null)
service.currentUser.name = data.username;
});
}
service.getSocialProviders = function () {
return Backand.getSocialProviders()
};
service.socialSignin = function (provider) {
Backand.setRunSignupAfterErrorInSigninSocial(false); //by default run sign-up if there is no sign in
return Backand.socialSignin(provider)
.then(function (response) {
loadUserDetails();
return response;
});
};
service.socialSignup = function (provider) {
return Backand.socialSignUp(provider)
.then(function (response) {
loadUserDetails();
return response;
});
};
service.signin = function (username, password) {
return Backand.signin(username, password)
.then(function (response) {
loadUserDetails();
return response;
});
};
service.signup = function (firstName, lastName, username, password, parameters) {
return Backand.signup(firstName, lastName, username, password, password, parameters)
.then(function (signUpResponse) {
return service.signin(username, password)
.then(function () {
return signUpResponse;
});
});
};
service.changePassword = function (oldPassword, newPassword) {
return Backand.changePassword(oldPassword, newPassword)
};
service.requestResetPassword = function (username) {
return Backand.requestResetPassword(username)
};
service.resetPassword = function (password, token) {
return Backand.resetPassword(password, token)
};
service.logout = function () {
Backand.signout().then(function () {
angular.copy({}, service.currentUser);
});
};
});
}());
和
ProfileModel.signup($scope.user.title, 'last', $scope.user.email, $scope.user.password, parameters)
.then(
function(resp){
console.log(resp);
}
);
我得到
Object {access_token: "epn2SW9XHgYj0RBtTv2tGHFmZATrSYqrA79qYnRckBVEaY8is-…m8B7Ko_NTRP-Salr0kh1ppCnOyQKnmzluCpmXOYd7BO7qAdkw", token_type: "bearer", expires_in: 86400, appName: "testthurst", username: "aero47@gmail.com"…}
access_token: "epn2SW9XHgYj0RBtTv2tGHFmZATrSYqrA79qYnRckBVEaY8is-wPWU4sBrnhtNJ8UsqvOeE5_1j_CnTd-HzSfimw_3t4Y9iuOn2N74rb2CCPV0hBFXUOQG1-JLnyqW7kWOc43DRteswmwLqVLRcln6KuHThUeW0wwop2XNiP6NwTsqi-2uokD65QJzoLDWUGEeZkpwZYYwGkXLW7I79INkguVkBauzafOm-vmm8B7Ko_NTRP-Salr0kh1ppCnOyQKnmzluCpmXOYd7BO7qAdkw"
appName: "testthurst"
expires_in: 86400
firstName: "TestUser"
fullName:"TestUser last"
lastName:"last"
regId:
374601
role:"User"
token_type:"bearer"
userId:null
顺便说一句,用户出现在“注册用户”表中,但不在“对象”部分的“用户”表中。
当“userId”为空时,我总是得到相同的结果。有谁知道我为什么会收到这个错误?