ios - 如何在 Swift 中更改 PFUser 密码?

标签 ios swift parse-platform pfuser

我试过更新 PFUser 电子邮件的方式,甚至尝试过转换 obj-c 代码(来自其他问题);都没有用。我也不知道如何使用 Cloud Code(好吧......我安装了它,但我不知道如何将信息传递到 Cloud Code 或如何使用 JavaScript)。有没有一种方法可以在不发送重置电子邮件的情况下更新用户密码?

最佳答案

出于安全原因,您不能以这种方式更改用户密码。你有两个选择

  • 密码重置邮件

  • 云码重置密码功能

据我所知,您不了解 JavaScript,这里有一个云代码函数,您可以使用它来重置用户密码,以及使用 Swift 调用该函数的方法。

函数(在 JavaScript 中):

Parse.Cloud.define("changeUserPassword", function(request, response) {
  // Set up to modify user data
  Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("username", request.params.username);  // find all the women
query.first({
  success: function(myUser) {
    // Successfully retrieved the object.
myUser.set("password", request.params.newPassword);

myUser.save(null, {
        success: function(myUser) {
          // The user was saved successfully.
          response.success("Successfully updated user.");
        },
        error: function(myUser, error) {
          // The save failed.
          // error is a Parse.Error with an error code and description.
          response.error("Could not save changes to user.");
        }
      });

  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});
});

调用上述函数的Swift代码:

PFCloud.callFunctionInBackground("changeUserPassword", withParameters: ["username" : "MyCoolUsername", "newPassword" : passwordField.text]) {
  (result: AnyObject?, error: NSError?) -> Void in
  if (error == nil) {
    // result is "Successfully updated user."
  }
}

祝你好运!

关于ios - 如何在 Swift 中更改 PFUser 密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28490228/

相关文章:

ios - 升级到 Unity 4.6.1 后 Xcode 6.1.1 链接器错误 : entry point (_main) undefined. for architecture armv7

ios - 动态文本字段创建和访问 Swift 4 中的那些字段

ios - Xamarin.iOS UIPopoverPresentationController 异常

xcode - Parse.com 入门项目在 xcode 6.3 上出现 Cannot invoke 'subscribeToChannelInBackground' 编译器错误

swift - 准备转场

c# - 停止 Xamarin.Forms 中的 IOS 弹跳

ios - 在 Swift 中动画 MapKit 注释坐标变化?

swift - NSTableView 显示每一行中的最后一个对象

ios - Swift:当应用程序在后台时调用 .requestLocation()

ios - Parse.com iOS localDatastore 仅固定,启用后不查找对象。 (也无法取消固定,因为它也找不到对象)