我尝试将某些测试用户的密码重置为已知状态以进行集成测试。但是,行
user.set("password", "testpassword");
使保存请求失败,并显示:
错误域=解析代码= 141"无法完成操作。 (解析错误141。)"
以下是相关的beforeSave代码:
Parse.Cloud.beforeSave(Parse.User, function(request, response) {
var user = request.object;
Parse.Cloud.useMasterKey();
if (user.get("username").substring(0, 4) === "test") {
console.log("overwriting password for test user.");
user.set("password", "testpassword");
}
response.success();
});
答案 0 :(得分:0)
对于代码141的完整写入,请查看我的其他帖子: https://stackoverflow.com/a/25360806/3204895
但在这种情况下,我猜你只是以Parse不允许的方式访问字段,我看到你已经使用了主密钥,所以ACL不应该阻止你,但请尝试使用保留的方法来访问用户名并设置密码:
if (user.getUsername().substring(0, 4) === "test") {
console.log("overwriting password for test user.");
user.setPassword("testpassword");
}
如果是response.success发生在错误的位置,虽然代码看起来很好,但是承诺了async:
user.save({
password: "testpassword"
}).then(function(savedUser) {
// The save was successful.
response.success(savedUser.getUsername() + "now has a password of 'testpassword'");
}, function(error) {
// The save failed. Error is an instance of Parse.Error.
response.error(user.getUsername() + " saving failed with an error | code: " + error.code + " | message: " + error.message);
});