1

我正在使用新的Firebase登录。数据库中有两个类别。 “厨师”和“顾客”。 “Cooks”有一个CookViewController,“Customers”有一个customerViewController。我需要知道此电子邮件属于哪个类别,因此登录后,segueCookViewControllerCustomerViewController。下面是登录代码,但我不知道如何判断电子邮件属于哪个类别。谢谢!Firebase如何验证要登录的电子邮件属于数据库中的哪个类别?

@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) 

       } 

} 

数据结构如下:

enter image description here

回答

3

如何让你的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 
      }.... 
      } 
     } 

所以,你可以在厨师节或客户节或任一检查在用户部分本身的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 

       } 
      } 
     }) 
+0

嗨达罗毗荼人,听起来不错!让我试着让你知道。我在工作后会接受你的答案。周末愉快! – developermike

+0

很高兴帮助,删除您以前的评论...:)\ – Dravidian

相关问题