快速从数据库中删除PFUser对象 [英] Deleting PFUser objects from database in swift

查看:79
本文介绍了快速从数据库中删除PFUser对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始快速处理服务器,当用户为我的应用程序创建帐户时,我正在使用解析服务器来存储用户数据库.我有一个称为注册的功能,该功能链接到一个注册按钮,该按钮可以正常工作并将用户的信息正确存储到我的解析数据库中.

I just started working with servers in swift and I'm using parse server to store a database of users when they create an account for my app. I have this function called sign up that is linked to a sign up button which works fine and properly stores user's info into my parse database.:

@IBAction func signUp(_ sender: AnyObject) {

   //I first check to see if the users left any of the fields blank

    if firstName.text == "" || lastName.text == "" || email.text == "" || userName.text == "" || password.text == "" {

        createAlert(title: "Error in form", message: "Please fill in all text fields")


    //If everything is filled in
    }else{


        let user = PFUser()
        user.username = userName.text
        user["firstname"] = firstName.text
        user["lastname"] = lastName.text
        user.email = email.text
        user.password = password.text


        user.signUpInBackground(block: { (success, error) in                
            if error != nil {

                var displayErrorMessage = "Please try again later."

                if let errorMessage = (error! as NSError).userInfo["error"] as? String {

                    displayErrorMessage = errorMessage
                }

                self.createAlert(title: "Signup error", message: displayErrorMessage)

            }else{
                print("User signed up")
            }
        })
    }

}

任何人都可以帮助我编写一个函数,该函数删除指定的用户或遍历所有用户的许多循环并将其删除.

Can anyone help me write a function that deletes a specified user or many loops through all users and deletes them.

谢谢

推荐答案

请勿将该代码放在客户端上. uck.

Don't put that code on a client. Yuck.

您要非常小心地保护删除用户.如果确实需要,请将其放入云代码中,并进行验证以确保其正确使用.

Deleting a user is something you want to safeguard very carefully. Put that in cloud code if you really need it, and do validation to ensure it's used properly.

也就是说,用户只能提出删除自己用户的请求.制作一个具有参数userId的云代码函数,并针对request.user.id检查该参数.如果它们不匹配,则返回错误.否则,您可以在该User上调用destroy方法.

I.e., a user should only be able to make the request to delete their own user. Make a cloud code function that has the parameter userId, and check that param against request.user.id. If they don't match, return an error. Otherwise you can call the destroy method on that User.

您还应该放置CLP以仅允许主键删除User对象.

You should also put a CLP in place to only allow the master key to delete a User object.

这篇关于快速从数据库中删除PFUser对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆