Simple login Firebase

3

I already have a main login with Firebase auth. But I need to implement another login inside that system because the client can add other administrators. The login will be simple, just check the password and email.

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 Jbase Firebase looks like this: parent and child:

{
    "rafael@gmailcom": {
        "ativo": true,
        "codigo": "rafael@gmailcom",
        "dataNascimento": 944515274,
        "email": "[email protected]",
        "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 not get it to bring the desired user.

    
asked by anonymous 16.02.2017 / 23:22

1 answer

1

Firebase does not allow you to do a Query based on 2 conditions. Which means you will need to log in in 2 steps:

1.Find 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
            }
        });
}
    
24.02.2018 / 11:42