【问题标题】:Backand user object not associated with custom user object if created through API如果通过 API 创建,Backand 用户对象不与自定义用户对象关联
【发布时间】:2016-02-20 00:24:37
【问题描述】:

我创建了一个自定义的“用户”对象,我知道它与 backand 的用户对象相关联。但是,当我使用 Backand 的 SDK 从我的应用程序中创建它们时,我可以看到在 Backand 的注册用户中创建了用户,但在我的自定义对象“用户”中没有看到

【问题讨论】:

    标签: backand


    【解决方案1】:

    这似乎是一个权限问题。也没有很好的记录。如果您的匿名访问设置为(只读)并且您从“创建我的应用程序用户”服务器端 javascript 中删除了 try catch 语句,您将在客户端中收到 401 错误。将匿名访问设置为公开,它首先尝试。可能有更好的方法来做到这一点,但我仍在研究它我不想给匿名用户那么多的访问权限。但它肯定证明这是权限问题。

    【讨论】:

    • 这成功了 - 更新了对“用户”的匿名访问...感谢 Eric!
    【解决方案2】:

    确保您在 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 {};
    }
    

    【讨论】:

    • 感谢您的回复,我检查了所有安全操作都是默认操作和您上面提到的(名称、条件、触发事件等)另外,在安全操作中,您可以测试右侧的操作,我看到在 backand 的用户对象以及我创建的自定义对象中都创建了一个对象。有什么想法,为什么它通过网络服务调用失败?
    • 这是从我的应用程序调用网络服务的代码 $scope.signup = function (user, signUpToken) { return $http({ method: 'POST', url : Backand.getApiUrl() + ' /1/user/signup',标题:{ SignUpToken:Signtoken },数据:{ firstName:user.firstName,lastName:user.lastName,email:user.email,密码:user.password,confirmPassword:user.password,} })
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多