Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 将user.roles设置为用户在注册时选择的值_Meteor - Fatal编程技术网

Meteor 将user.roles设置为用户在注册时选择的值

Meteor 将user.roles设置为用户在注册时选择的值,meteor,Meteor,我不知道如何将user.roles设置为用户完成注册时选择的值。下面的代码可以工作,但是它将角色设置为教师和学生,而不是用户选择的角色。我正在使用: 阿兰宁:角色 用户帐户:引导 用户帐户:引导 路径:server.startup.js Meteor.startup(function () { console.log('Running server startup code...'); Accounts.onCreateUser(function (options, user) { Ro

我不知道如何将user.roles设置为用户完成注册时选择的值。下面的代码可以工作,但是它将角色设置为教师和学生,而不是用户选择的角色。我正在使用:

  • 阿兰宁:角色
  • 用户帐户:引导
用户帐户:引导

路径:
server.startup.js

Meteor.startup(function () {

console.log('Running server startup code...');

Accounts.onCreateUser(function (options, user) {
Roles.setRolesOnUserObj(user, ['student','teacher']);

if (options.profile) {
// include the user profile
user.profile = options.profile
}

// other user object changes...
// ...

return user;
});

});
AccountsTemplates.addField({
_id: "roles",
type: "radio",
displayName: "Account type",
required: true,
select: [
{
text: "Student",
value: "student",
}, {
text: "Teacher",
value: "teacher",
}
],
});
路径:
lib/config/at_config.js

Meteor.startup(function () {

console.log('Running server startup code...');

Accounts.onCreateUser(function (options, user) {
Roles.setRolesOnUserObj(user, ['student','teacher']);

if (options.profile) {
// include the user profile
user.profile = options.profile
}

// other user object changes...
// ...

return user;
});

});
AccountsTemplates.addField({
_id: "roles",
type: "radio",
displayName: "Account type",
required: true,
select: [
{
text: "Student",
value: "student",
}, {
text: "Teacher",
value: "teacher",
}
],
});

AccountsTemplates.addField
将字段存储在
profile
下,因此您应该能够通过如下方式获取所选角色:

Accounts.onCreateUser(function (options, user) {

   if (options.profile && options.profile.roles) {
      // include the user profile
      Roles.setRolesOnUserObj(user, options.profile.roles);
   }
}
这里有一个类似的问题:


您是否尝试根据用户选择的值向用户添加角色?这就是线角色;那不行吗?你似乎在分配这两个角色?是的,我不知道如何使用用户选择并将其传递给accross,以便我分配特定的选择。谢谢@smoksnes,你真的帮助了我。我被难住了。这完全解决了我的问题。太好了。很乐意帮忙。玩流星吧!