我正在建立一个受限注册。我希望具有在网址中传递的特定代码的用户能够注册,而不是其他人。我正在使用 accounts
包。
我可以在 Accounts.onCreateUser
方法中阻止帐户创建。我正在寻找一种方法来告诉服务器客户端是否有授权的注册代码。使用经典表单(电子邮件+密码),我可以添加一个额外的隐藏字段。如果用户使用 Facebook 进行注册,我怎样才能获得相同的结果?
由于 Meteor 不使用 cookie,因此我无法将此信息存储在服务器可以访问的 cookie 中。 Session
变量不可在服务器端访问。由于我无法控制创建 account-facebook
时发送的内容,因此我无法在客户端使用我在以下情况下传递的 Session
变量:用户按下注册。
有什么想法吗?
最佳答案
只需将特殊 token 添加到传递给 Accounts.createUser()
的用户对象即可:
var user = {
email: email,
password: password,
profile: {
token: token
}
};
Accounts.createUser(user, function (error, result) {
if (error) {
console.log(error)
}
});
在服务器端,您可以在Accounts.onCreateUser()
中访问它:
Accounts.onCreateUser(function(options, user) {
console.log(options);
console.log(user);
});
我认为您可以在 options 变量中找到您的 token ,因此它将是 options.profile.token
。
关于cookies - Meteor 在客户端和服务器之间共享 session 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35026321/