Meteor 1.0-自定义身份验证规则



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

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

有点像:

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

您可以使用Accounts.registerLoginHandler方法来实现这一点。此函数允许开发人员添加自定义身份验证方法。退房https://meteorhacks.com/extending-meteor-accounts.html想要一篇更详细的好文章。

您可能希望继续使用loginWithPassword,并注册一个类似于Meteor帐户密码包中的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
  }
});

accounts包通常对MongoDB有很多依赖性,但您应该能够从包中拼凑出各种方法,以使auth发挥作用。

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

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

最新更新