Firebase从电子邮件中获取uid

时间:2017-06-17 19:45:00

标签: java android firebase firebase-realtime-database

我想输入一封电子邮件,以便能够通过电子邮件添加朋友。

这是我到目前为止所得到的:

'use strict';

/*
 * Defining the Package
 */
var Module = require('meanio').Module;

var Dashboard = new Module('dashboard', ['zingchart-angularjs']);

/*
 * All MEAN packages require registration
 * Dependency injection is used to define required modules
 */

Dashboard.register(function(app, auth, database, circles) {

  //We enable routing. By default the Package Object is passed to the routes
  Dashboard.routes(app, auth, database, circles);

  //We are adding a link to the main menu for all authenticated users
  Dashboard.menus.add({
    title: 'dashboard',
    link: 'dashboard',
    roles: ['authenticated'],
    menu: 'main'
  });

  Dashboard.angularDependencies(['zingchart-angularjs']);

  return Dashboard;
  });

如果我直接输入一个uid,但是我希望我的输入是一封电子邮件并从中获取一个uid,或者如果有其他解决方案,请提示。

这是数据库结构的样子: Image of firebase db

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

要按用户的电子邮件地址搜索用户,您需要订购/过滤该属性:

Query query = mRef.orderByChild("email").equalTo("example@example.com");
query.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        // There may be multiple users with the email address, so we need to loop over the matches
        for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
            System.out.println(userSnapshot.getKey());
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        // Getting Post failed, log a message
        Log.w(TAG, "find email address:onCancelled", databaseError.toException());
        // ...
    }
});

与问题没有直接关系,但请重新构建数据以删除朋友和个人资料的嵌套。出于多种原因,最好将Firebase数据结构保持平稳,并将用户配置文件与朋友列表分开。

/users
  uid1: ... profile for user 1
  uid2: ... profile for user 2
/friends
  uid1: ... friends list for user 1
  uid2: ... friends list for user 2