我创建了一个我知道与 backand 的用户对象相关联的自定义“用户”对象。但是,当我使用 Backand 的 SDK 从我的应用程序创建它们时,我可以看到在 Backand 的注册用户中创建了用户,但在我的自定义对象“用户”中没有
问问题
224 次
2 回答
1
这似乎是一个权限问题。也没有很好的记录。如果您的匿名访问设置为(只读)并且您从“创建我的应用程序用户”服务器端 javascript 中删除了 try catch 语句,您将在客户端中收到 401 错误。将匿名访问设置为公开,它首先尝试。可能有更好的方法来做到这一点,但我仍在研究它我不想给匿名用户那么多的访问权限。但它肯定证明这是权限问题。
于 2016-02-26T15:57:38.193 回答
1
确保您在 Security & Auth 中具有以下安全操作,并且它们的条件设置为 true:事件 - 创建期间,名称 - 创建我的应用用户代码:
/* globals
$http - Service for AJAX calls
CONSTS - CONSTS.apiUrl for Backands API URL
Config - Global Configuration
*/
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {
// When a new user registers, add her to the users object.
// If you are using a different object for your users then change this action accordingly.
if (parameters.sync)
return {};
if (!parameters)
parameters = {};
parameters.email = userInput.Username;
parameters.firstName = userInput.FirstName;
parameters.lastName = userInput.LastName;
try{
var response = $http({
method: "POST",
url:CONSTS.apiUrl + "/1/objects/users",
params: {parameters: {"sync": true}},
data: parameters,
headers: {"Authorization": userProfile.token}
});
}
catch(err) {
// register user even if there is an error or no users object
}
return {};
}
事件 - 更新期间,名称 - 更新我的应用用户代码:
/* globals
$http - Service for AJAX calls
CONSTS - CONSTS.apiUrl for Backands API URL
Config - Global Configuration
*/
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {
// When a registered user is changed, change your users object as well.
// If you are using a different object for your users then change this action accordingly.
// Get the user id by the user's email
var currentUser = $http({
method: "GET",
url:CONSTS.apiUrl + "/1/objects/users",
params: {filter:[{"fieldName":"email", "operator":"equals", "value": userInput.Username }]},
headers: {"Authorization": userProfile.token}
});
if (currentUser.data.length == 1) {
var currentUserId = currentUser.data[0].__metadata.id;
var response = $http({
method: "PUT",
url:CONSTS.apiUrl + "/1/objects/users/" + currentUserId + "",
params: {},
data: {"firstName": userInput.FirstName, "lastName": userInput.LastName },
headers: {"Authorization": userProfile.token}
});
}
return {};
}
事件 - 删除期间,名称 - 删除我的应用用户代码:
/* globals
$http - Service for AJAX calls
CONSTS - CONSTS.apiUrl for Backands API URL
Config - Global Configuration
*/
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {
// When a registered user name is deleted, delete her from your users object as well.
// If you are using a different object for your users then change this action accordingly.
// Get the user id by the user's email
var currentUser = $http({
method: "GET",
url:CONSTS.apiUrl + "/1/objects/users",
params: {filter:[{"fieldName":"email", "operator":"equals", "value": dbRow.Username }]},
headers: {"Authorization": userProfile.token}
});
if (currentUser.data.length == 1) {
var currentUserId = currentUser.data[0].__metadata.id;
var response = $http({
method: "DELETE",
url:CONSTS.apiUrl + "/1/objects/users/" + currentUserId + "",
params: {},
headers: {"Authorization": userProfile.token}
});
}
return {};
}
于 2016-02-21T08:47:52.517 回答