我正在研究新的Firebase
登录。数据库中有两个类别。“厨师”和“客户”。“ Cooks”具有CookViewController,而“ Customers”具有customerViewController。我需要知道此电子邮件属于哪个类别,因此在登录segue
到CookViewController
或之后CustomerViewController
。以下是登录代码,但我不知道如何区分电子邮件所属的类别。谢谢!
@IBAction func loginPressed(sender: AnyObject) {
if let email = emailField.text where email != "", let password = passwordField.text where password != "" {
FIRAuth.auth()?.signInWithEmail(email, password: password, completion: { (user, err) in
if err != nil {
print(err)
} else {
// Here I need to know whcih view Controller to Segue to:
self.performSegueWithIdentifier(identifier: String, sender: self)
}
}
数据结构如下:
如何使您的JSON像:-
yourApp:{
cooks:{
email1:true,
email3:true,
email4:true,
email7:true,
email8:true},
customers:{
email2:true,
email12:true,
email13:true,
email4:true,
email8:true},
users:{
uid1:{
email : [email protected],
isCook: true
},
uid2:{
email : [email protected],
isCook: false
}....
}
}
因此,您可以签入cooks部分,customer部分或users部分下的uid,然后与该isCook
节点相关,如果他是->转到cookViewController,否则转到customerViewController
最简单的方法是检入uid:-
FIRDatabase.database().reference().child("users/\(FIRAuth.auth()!.currentUser!.uid)/isCook").observeSingleEventOfType(.Value,withBlock:{(snap) in
if let isThisUserCook = snap.value as? Bool //or String{
if isThisUserCook == true{
//segue to cookVC
}else{
//segue to customerVC
}
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句