Ios 在用户注册时将用户添加到角色
是否可以在用户注册时将其添加到角色?并将其添加为基本用户 我已经试了一段时间了,但似乎想不出来 对于我的注册脚本,我使用以下代码:Ios 在用户注册时将用户添加到角色,ios,swift,parse-platform,Ios,Swift,Parse Platform,是否可以在用户注册时将其添加到角色?并将其添加为基本用户 我已经试了一段时间了,但似乎想不出来 对于我的注册脚本,我使用以下代码: func SignUp() { let user = PFUser() user.username = UsernameTextField.text user.password = PasswordTF.text user.email = EmailTF.text user.signUpInBackgroundWithB
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)
}
}
}
如果我需要提供更多信息,请告诉我。在用户在后台注册后,您可以在“If error==nil”条件中执行此操作 下面将创建一个角色。roleName在您的案例中是“基本用户”
var role = PFRole.roleWithName(roleName, acl:roleACL)
role.users.addObject(user)
role.saveInBackground()
要设置角色ACL(例如),请查看注释中的api以了解更多要使用的方法
var roleACL = PFACL.ACL()
roleACL.setPublicReadAccess(true)
好的,谢谢你。我对这个很陌生。如何定义ACL?我不需要将用户另存为用户名吗?比如说,如果我说注册用户获得了角色基本用户/用户,你是否试图将你的用户分为两类,管理员和基本用户?有关更具体的方法,请查看包含API的链接。没有找到它。