gpt4 book ai didi

swift - 删除解析 PF 用户帐户

转载 作者:行者123 更新时间:2023-11-30 13:48:15 25 4
gpt4 key购买 nike

我有一个应用程序(用 Swift 编写),它使用 Parse 并允许用户创建帐户。我希望用户可以选择删除他们的帐户,但似乎无法弄清楚并且不确定我做错了什么。我希望用户必须验证他们的电子邮件和密码才能发生这种情况。一旦他们删除了自己的帐户,就会弹出一个警报,然后一旦用户取消警报,他们就会返回到登录屏幕并退出应用程序。

这是我尝试过的:

   @IBAction func deleteAccount(sender: AnyObject) {

if PFUser.currentUser()?.username == emailAddressTextField.text && PFUser.currentUser()?.password == passwordTextFieldOne.text && PFUser.currentUser()?.password == passwordTextFieldTwo.text {

PFUser.currentUser()?.deleteInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in

if success {

let alertController = UIAlertController(title: "Success!", message: "Now Please Login", preferredStyle: .Alert)

let enterAppAction = UIAlertAction(title: "OK", style: .Default, handler: { (UIAlertAction) -> Void in

dispatch_async(dispatch_get_main_queue(), { () -> Void in
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Login")
self.presentViewController(viewController, animated: true, completion: nil)
})
})

alertController.addAction(enterAppAction)

self.presentViewController(alertController, animated: true, completion: nil)

} else {

print(error)
self.displayAlert("Account deletion failed", message: "Please try again", actionTitle: "OK")

}
})
}
}

最佳答案

您可以创建一个云函数来验证用户是否正确输入了当前密码,并让它向 iOS 返回成功/错误,此时您可以删除该帐户(前提是成功完成密码检查)。这是 relevant Parse forum post .

来自引用的帖子:

Parse.Cloud.define(FUNCTION_PASSWORD_CHECK, function(request, response) 
{
var password = request.params.password;

Parse.User.logIn(request.user.getUsername(), password, {
success: function(results)
{
response.success(true);
},
error: function() {
response.success(false);
}
});
});

注意:您可以在 iOS 上执行类似的登录功能,但如果用户输入错误的密码(我不确定),这可能会扰乱 PFUser.currentUser() 。此外,引用的函数使用 request.user,建议这样做(即不要将用户作为参数传递),以便它仅适用于具有 session 的用户。

关于swift - 删除解析 PF 用户帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34646169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com