Question:
I already have a main login with Firebase auth. But I need to implement another login within that system as the customer can add other admins. The login will be simple, just check if the password and email match.
I have this method that logs in:
public void retrive(String uid, String senha) {
raiz
.child(CHILD) // ex: adms
.child(uid) // ex: rafael@email
.equalTo(senha,"senha")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
// ok
}else {
// false
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
//false
}
});
}
My Firebase Json is like this: father admin and children:
{
"rafael@gmailcom": {
"ativo": true,
"codigo": "rafael@gmailcom",
"dataNascimento": 944515274,
"email": "rafael@gmail.com",
"nome": "Rafael Aparecido da silva",
"privilegios": {
"ACESSO_FINANCEIRO": true,
"AGENDAR_CONSULTA": false,
"CADASTRO_PACIENTE ": false,
"CADASTRO_PACIENTE_": false,
"MANTER_ADM": false,
"RECEBER_PAGAMENTO": true
},
"senha": "teste"
}
}
I can't get it to bring the desired user.
Answer:
Firebase does not allow you to do a Query based on 2 conditions. Which means you will have to login in 2 steps:
1.Search for the user with this ID
2.Check if the password is correct:
public void retrive(String uid, String senha) {
raiz.child(CHILD) // ex: adms
.child(uid) // ex: rafael@email
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.child("senha").getValue() == Senha) {
// ok
}else {
// false
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
//false
}
});
}