2016-01-13 74 views
0

是否有可能将用户添加到角色,当他们注册?并将它们添加为基本用户?将用户添加到角色,当他们注册

我一直在尝试,现在有一阵子,但似乎无法推测出来。

对于我的注册脚本,我使用下面的代码:

func SignUp() { 

    let user = PFUser() 
    user.username = UsernameTextField.text 
    user.password = PasswordTF.text 
    user.email = EmailTF.text 


    user.signUpInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in 
     if error == nil { 


      // Hooray! Let them use the app now. 
      let alertcontroller = UIAlertController(title: "Russeradar", message: "Din bruker er nå opprettet! Du kan nå logge in" , preferredStyle: UIAlertControllerStyle.Alert) 
      alertcontroller.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
      self.presentViewController(alertcontroller,animated: true, completion: nil) 


     } else { 
      // Examine the error object and inform the user. 
      let alertcontroller = UIAlertController(title: "Russeradar", message: "Din bruker kunne ikke opprettes. Prøv på nytt senere!" , preferredStyle: UIAlertControllerStyle.Alert) 
      alertcontroller.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
      self.presentViewController(alertcontroller,animated: true, completion: nil) 
     } 
    } 

} 

如果我需要提供更多的信息,让我知道。

回答

0

那么你可以在做你的“如果错误==无”条件,用户已经在后台签约后

下面将创建一个角色。角色名是你的情况

var role = PFRole.roleWithName(roleName, acl:roleACL) 
role.users.addObject(user) 
role.saveInBackground() 

要设置角色访问控制列表(对于如)“基本用户”看看在多种方法的注释的API来使用

var roleACL = PFACL.ACL() 
roleACL.setPublicReadAccess(true) 
+0

Okei,谢谢。我对此很新。我如何定义ACL?而且我不需要将用户保存为用户名吗?就像如果我要说的是,注册用户得到了角色基本用户/用户 –

+0

你是不是想你的用户分手分为两类,管理员用户与普通用户? – MJJLAM

+0

是的,这是正确的 –

相关问题