我有2个应用程序' service [server-app]'和'网站[client-app]'与流星群相连,我连接了服务'应用mongodb。我正在使用account-ui登录并通过网站注册'应用。下面提供的是我的代码,这是正确的方法
网站申请
Accounts.onCreateUser(function(options, user) {
var usr = ddpconn.call('CreateUser', user); // ddp cluster connection to the service app
return usr;
});
服务申请
Meteor.methods({
CreateUser: function (user) {
var invited = Invitations.findOne({"user_id":user._id});
if(invited){
// Updates the subdoc of invited user
Meteor.users.update({"_id": invited.user_id,"rules._id":usr.rules[0]._id},{ $inc:
{"rules.$.lineup": 1} });
Invitations.update({"user_id":invited.user_id},{$set:{"updated_at":new Date()}});
// Adds a rules subdoc to the user which creates an account
user.rules = [ { "_id" : new Mongo.ObjectID()._str, "lineup" :1} ]
return user;
}
} else {
// Adds a rules subdoc to the user which creates an account
user.rules = [ { "_id" : new Mongo.ObjectID()._str, "lineup" : 1} ]
return user;
}
}
});