注册时是否可以将用户添加到角色?并将它们添加为基本用户?
我已经尝试了一段时间,但似乎无法弄明白。
对于我的注册脚本,我使用以下代码:
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 :(得分:0)
你可以在你的&#34中做到这一点;如果错误== nil"用户在后台注册后有条件的
下面会创建一个角色。 roleName是"基本用户"在你的情况下
var role = PFRole.roleWithName(roleName, acl:roleACL)
role.users.addObject(user)
role.saveInBackground()
设置角色ACL(例如)在评论中查看api以获取更多使用方法
var roleACL = PFACL.ACL()
roleACL.setPublicReadAccess(true)