Configure ACLs for the new Parse user in swift

I am currently having a problem with users having access to another user's objects in my application.

I know how to set an ACL when a user creates an object when it is already registered in the application, but I don't know how to set an ACL for a subscription. When I set the navigation header to display the user’s ["BusinessName"] column, I get company names from another user column created ... thanks for your help !! very grateful!

 @IBAction func signupFinalButton(sender: AnyObject) {

  var newUser = PFUser()
  newUser.username = username
  newUser.password = password
  newUser.email = email
  newUser["FirstName"] = firstName
  newUser["LastName"] = lastName
  newUser["BusinessName"] = businessName
  newUser["City"] = city
  newUser["State"] = state

  // This isn't seeming to work...
  newUser.ACL = PFACL(user: PFUser.currentUser()!) 
  or this 
  newUser.ACL = PFACL(user: PFUser())

  newUser.signUpInBackgroundWithBlock({ (succeed, error) -> Void in

or maybe I'm asking parsing wrong? I am new to this.

     func navTitle () {
     var user = PFUser.currentUser()
     var query = PFQuery(className:"_User")
     query.findObjectsInBackgroundWithBlock {
    (objects: [AnyObject]?, error: NSError?) -> Void in

     if error == nil {
     if let objects = objects as? [PFObject] {
     for object in objects {

     self.homeScreen.title = object["BusinessName"] as! String?
      }
     }else {

     self.homeScreen.title = "Home"
     }
+4
source share
2 answers

You need to set the ACL after that is signed by signUp.

,

func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser)

// set the ACL for the newly created user

newUser.ACL = PFACL(user: PFUser.currentUser()!)

//Then you can save the user, ie saveEventaully 

PFSignUpViewController - ACL signUpInBackgroundWithBlock, .

, , .

let role = PFRole(name: user.objectId!, acl: roleACL)
role.users.addObject(user)

, .

+2

@DogCoffee , .

didFinishLaunchingWithOptions , ACL. ACL , , .. .

, Parse, :

ParseCrashReporting.enable()
Parse.enableLocalDatastore()

Parse.setApplicationId("<YOUR APP ID>", clientKey: "<YOUR CLIENT KEY>")

//Always set the ACL value to the current user
PFACL.setDefaultACL(PFACL(), withAccessForCurrentUser: true)  

, . !

+3

All Articles