doupi8598 2016-11-29 15:05
浏览 61
已采纳

解析(.com)php SDK“主密钥”而不是用户查询的密码

I can't seem to find any documentation on this. All I simply look to do is update a users info within my table without having the need of the users password. I'd like to simply look up the email of the user and update information for that user. Not change the password but other columns in the table associated with that user.

Example query:

$query = new ParseQuery("_User");
$query->equalTo("username", "user001");
foreach ($result as $doc) {
$doc->set('name', "new info");
$doc->save();
}

Through Parse's php SDK, how do I change a users information just by knowing the email/username of the user? without logging in?

I heard you can do this by using your "master key" instead of a password or through a cloud job but I don't know where to start with that.

I see in the API ref: save(boolean $useMasterKey = true) : null

Anyone have any ideas?

P.S: I have found this response but I'm still confused how to execute this (https://www.parse.com/questions/users-editing-other-users-in-javascript-sdk).

  • 写回答

1条回答 默认 最新

  • dongrunying7537 2016-12-01 16:03
    关注

    Modifying a user should probably be done on the server side using a cloud function. You can make a cloud function in javascript on your parse server by editing the cloud/main.js file. More documentation here.

    Basically, you can create a function like this:

    Parse.Cloud.define("modifyuser", function(request, response){
      var query = new Parse.Query(Parse.User);
      query.equalTo('objectId', request.params.objectId);
      query.find({
        useMasterKey: true,
        success: function(results){
          if(results.length>0){
            var user = results[0];
            user.set("SOMEPARAMETER",true);
            user.save().then(
                function(result){
                },
                function(error){
                    console.log("Error: " + error.code + " " + error.message);
                });
            }
          }
        },
        error: function(error){
                response.error('query error: '+ error.code + " : " + error.message);
        }
      });
    });
    

    And call this function from your client.

    $ParseCloud::run("modifyuser", ["objectId" => "THEUSEROBJECTID"]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起