I found this code that allows you to create an account on the deviceID:
private void queryAccountExistence(final String email,final String password) {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users");
Query query = ref.orderByChild("deviceID").equalTo(deviceID);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
//la device est déjà enregistré
Toast.makeText(RegisterActivity.this,
"Cette device est déjà lié à un compte, connectez-vous",
Toast.LENGTH_SHORT).show();
} else {
//Aucune deviceID trouvé
createAccount(email, pass);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
Now how to make it possible to create a maximum of 3 accounts on the deviceID?
CodePudding user response:
Now how to make it possible to create a maximum of 3 accounts on the deviceID?
Simply by checking:
if (snapshot.exists()) {
if (snapshot.getChildrenCount() <= 3) {
createAccount(email, pass);
} else {
Log.d("TAG", "You reached the maximum limit of three account per deviceID.");
}
}