java—基于电子邮件查找用户数据

nr9pn0ug  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(263)

我在loginpage中收到了一个用户的电子邮件,现在我想获取他的数据(用户数据包括:手机号码、姓名、日期和最重要的类型(业务/常规)),根据我能知道的类型,我应该将用户重定向到哪里(如果用户的类型是business,那么我会将其发送到businesshomeactivity..)您可以看到我的数据库结构(每个uid包含email、bday、type、mpbile number),这是用户的信息,希望您能帮助我(java、android studio)谢谢!

c0vxltue

c0vxltue1#

很简单,你可以这样得到这个uid

FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(getActivity(), task -> {
                if (task.isSuccessful()) {

                   // here you get the logged-in user UID if login successful
                   String userUID = FirebaseAuth.getInstance().getCurrentUser().getUid()
                   // set the path of your database and get the UID from it
                   String path = FirebaseDatabase.getInstance().getReference("yourRootKey").child("User").child(userUID).child("Email")

                   //add a listener to get value
                   path.addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            // here you can get value from dataSnapshot as above you can achieve from onDataChange and check the type
                            // and navigate to user
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                           Log.e("onCancelled", databaseError.toException());
                        }
                   });

                } else {
                    // login failed display as toast
                }
            });

相关问题