【发布时间】:2016-08-27 09:40:06
【问题描述】:
这是我最后想要的:
{
"data" : {
"account" : {
"K1472290187836" : {
"created" : 1472290190043,
"id" : "K1472290187836"
}
},
"auth" : {
"d182ddec-f1c7-41c5-8b0e-198bfb5d9efe" : {
"account_id" : "K1472290187836",
"active" : true,
"created" : 1472290190043,
"id" : "d182ddec-f1c7-41c5-8b0e-198bfb5d9efe"
}
}
}
}
这是我的数据类:
public class Account {
public long created;
public String id;
public HashMap<String, Object> toMap() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", id);
map.put("created", ServerValue.TIMESTAMP);
return map;
}
}
public class Auth {
public String id;
public long created;
public boolean active;
public String account_id;
public HashMap<String, Object> toMap() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", id);
map.put("created", ServerValue.TIMESTAMP);
map.put("active", active);
map.put("account_id", account_id);
return map;
}
}
这是我的多地点更新:
final Auth auth = new Auth();
auth.id = FirebaseAuth().getCurrentUser().getUid();
auth.active = true;
auth.account_id = "K" + System.currentTimeMillis(); // TODO replace with proper id generator
final Account account = new Account();
account.id = auth.account_id;
HashMap<String, Object> newUserMap = new HashMap<String, Object>();
newUserMap.put("/data/account/" + account.id, account.toMap());
newUserMap.put("/data/auth/" + auth.id, auth.toMap());
FirebaseDatabase().getReference().updateChildren(newUserMap);
我需要的是在可以存储数据之前验证 data/account/$account_id/id 与 /data/auth/$auth_id/account_id 具有相同值的规则。
【问题讨论】:
标签: android firebase firebase-realtime-database firebase-security