【发布时间】:2017-05-14 04:08:30
【问题描述】:
我在 Firebase 中有一个数据库,其中包含单独的用户节点。在每个用户的节点中都将包含与他们相关的数据,并且是私有的。除此之外,我想创建一个节点,它只是注册电子邮件的集合。原因是当用户在登录 VC 上并且用户键入电子邮件时。如果电子邮件已经注册,图像视图将变为绿色。但是,如果电子邮件不在数据库中(或者如果它与电子邮件地址格式不匹配),则图像将为红色。
我先前问题的先前答案表明我需要更改“。”到电子邮件地址中的“,”。所以@gmail.com 将被存储为 gmail,com
我记下了。
FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
let email = firstContainerTextField.text ?? ""
let newString = email.replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
self.ref.child("users").child("allUsers").child(newString).setValue(true)
self.ref.child("users").child((user?.uid)!).setValue(["Email": email])
FIRAuth.auth()!.signIn(withEmail: email,
password: password)
} else {
//registration failure
}
这是来自新用户 VC 的代码(部分)。
所以说“用户”和“所有用户”的节点在 Firebase 控制台上看起来像这样
users
allUsers
bob@bob,com: true
ted@ted,com: true
“真实”部分只是为了让我可以将 bob@bob,com 放到数据库中……真实部分永远不会用于任何事情。
在登录 VC 时,我真的不知道该怎么做
之前的回答说要使用
hasChildren()
我使用了它,然后用谷歌搜索了如何处理它 我尝试使用类似的东西
ref.child("users").child("allUsers").queryEqual(toValue: newString)
.observe(.value, with: { snapshot in
if snapshot.hasChildren() {
for child in snapshot.children.allObjects as! [FIRDataSnapshot] {
....
}
});
但我似乎无能为力。
如何简单地查看 textfield.text == 电子邮件是否已存储在 firebase 中?
(比较时我确实将“.”转换为“,”)
【问题讨论】:
标签: swift firebase firebase-realtime-database firebase-authentication