2

我有一个流星应用程序,它使用 Neo4j 作为带有neo4jreactivity驱动程序的数据库。由于我没有使用 Mongo,Meteor.loginWithPassword(email, password, function(err) {...})因此不起作用。我的问题是:

如何定义自定义身份验证规则以登录应用程序?

有一些像:

customLogin(email, password, function() {...});
4

2 回答 2

3

您可以使用该Accounts.registerLoginHandler方法来完成此操作。此功能允许开发人员添加自定义身份验证方法。查看https://meteorhacks.com/extending-meteor-accounts.html以获得更详细的精彩文章。

您可能希望继续使用loginWithPassword,并在 Meteor 的 accounts-password 包中注册一个loginHandler类似的包(请参阅 Meteor 的实现),将调用Meteor.users.findOne(selector)替换为 Neo4j 中的数据库查找。

如果您想使用自定义登录方法,您的代码可能类似于此处的代码(出于此问题的目的进行了修改)。请注意,此代码不完整,也不是一种安全的身份验证方式:

// client-side

// This function can be called to log in your users, and will
// trigger the following
Meteor.loginWithNeo4j = function(email, password, callback) {
    //create a login request with the email and password passed in
  var loginRequest = {email: email, password: password};
  
  //send the login request
  Accounts.callLoginMethod({
    methodArguments: [loginRequest],
    userCallback: callback
  }); 
};  

// server-side

Accounts.registerLoginHandler(function(loginRequest) {
  // loginRequest is a JS object that will have properties
  // "email" and "password as passed in the client  code
  
  // -- here you can write code to fetch the user's ID from the database
 // take a look at https://github.com/meteor/meteor/blob/devel/packages/accounts-password/password_server.js#L61
 // to see how meteor handles password checking
  
  return {
    userId: userId
  }
});

帐户包通常对 MongoDB 有很多依赖关系,但是您应该能够将包中的各种方法拼凑起来以使身份验证工作。

于 2015-02-09T06:28:05.177 回答
0

要获取用户的对象,请使用:

Meteor.neo4j.query('MATCH (a:Player {_id: "kE3ypH4Um"}) RETURN a').get().a[0]
/* or by email */
Meteor.neo4j.query('MATCH (a:Player {email: "name@domain.com"}) RETURN a').get().a[0]

另请参阅更新的驱动程序 API

于 2015-09-26T17:40:17.107 回答