另一個孩子,我有一個登錄和登錄裏面我需要檢查,如果用戶爲了知道至極屬於「Administrador」或「Chofer」(firbase數據庫樹的孩子的)屏幕I'm要打開,我有以下代碼:檢查是否屬於一個按鍵或在火力
mAuth.signInWithEmailAndPassword(usuario, pass)
.addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(Login.this, "Los Datos administrados no son correctos",
Toast.LENGTH_SHORT).show();
mProgress.dismiss();
} else{
Toast.makeText(Login.this, "Bienvenido... ",
Toast.LENGTH_SHORT).show();
//loadAdmin(task.getResult().getUser());
mProgress.dismiss();
if(AdminFirebase.esAdmin(task.getResult().getUser())){
AdminFirebase.loadAdmin(task.getResult().getUser());
Intent intento=new Intent(Login.this, Principal.class);
intento.putExtra("Usuario", "administrador");
startActivity(intento);
}
else{
ChoferFirebase.loadChofer(task.getResult().getUser());
Intent intento=new Intent(Login.this, Principal.class);
intento.putExtra("Usuario", "chofer");
startActivity(intento);
}
}
}
});
,我有與它下面的一個問題的方法:
public boolean esAdmin(FirebaseUser user){
DatabaseReference adminRef= ref.child("Administradores");
if(adminRef.child(user.getUid()).getKey() == null) {
return false;
} else {
return true;
}
}
這裏其JSON結構從火力點:
"Administradores" : {
"2XPtAqaBDHXm8R5rLWjJ2pIzADi1" : {
"chapas" : "bbb222,idTaxi",
"email" : "gastondelacruz[email protected]",
"nombre" : "gaston",
"telefono" : "122323232"
}
},
"Choferes" : {
"6YWaOqBDDlOmrcpgm84dm5WipmH3" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F86?alt=media&token=4d9bbf4b-f884-459a-820a-ee1027668f1c",
"nombre" : "ccccc",
"taxi" : "aaa111"
},
"6lvl464H3IYfFJOBoE9tzl4IzVu1" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F35?alt=media&token=1bdb1d06-e4a5-41e7-a5ae-9f8a77d1f515",
"nombre" : "facuputito"
},
"7gOzX9azHSQLP9Enji0wZMVKYzz1" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F32?alt=media&token=7d6013a6-4063-4b1f-9171-209ede2562d6",
"nombre" : "test2"
},
"8iE2DPGY0OWh4sbRTyCtWaDyUct1" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F86?alt=media&token=f28567aa-5514-48f4-957d-b413f14867ee",
"nombre" : "bbbbb"
},
"BT1C40DMHRac7LRHuaQQmfeFe7H3" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F35?alt=media&token=5b160731-221a-44e2-9362-e5b4edf9dde9",
"nombre" : "name"
},
"LpD2brAzIPTwpP5BFLd0ie8lAX92" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F86?alt=media&token=1681459e-f25b-4ea3-9599-756cf6617a46",
"nombre" : "kakaka"
},
"MTYu8GWex8Ox3hXEPhjTwFlmx463" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F86?alt=media&token=2a0075c1-8e4a-4a21-9ea4-b3f03123989c",
"nombre" : "aaaaa"
},
"Ndtq2knyyMMs9AlU1ACTiSm4twE3" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F35?alt=media&token=c67af765-d9b3-4262-b047-01f1ec353dc6",
"nombre" : "facutragasable"
},
"jdzkv8PrHmYUuRU1lCgoGZgTeQ12" : {
"imagen" : "https://firebasestorage.googleapis.com/v0/b/taxiexpress-192df.appspot.com/o/fotos%2F35?alt=media&token=c67af765-d9b3-4262-b047-01f1ec353dc6",
"nombre" : "facu"
}
}
你能提供你的數據庫結構(JSON如果可能的話),並指出(在數據庫中),你在哪裏放置值,指示用戶是管理員或chofer? – koceeng
喜隊友,對不起,我剛纔看到這個延遲,我已經貼了JSON代碼,並添加了「adminRef」變量的值。 –