我使用这个roles meteor package,我不能让我的管理面板发行分配管理角色。流星(0.9.0.1):使用角色包
我目前得到的行为记录在管理用户被重定向到主页,而不是被显示的管理区。
如果我运行下面的代码我得到返回“假”,建议用户不是一个管理员用户:
Roles.userIsInRole(Meteor.user(), ['admin']);
如果我尝试在控制台上添加了角色,我得到这个:
Roles.addUsersToRoles("Nvu2wZRg3K2wd4j4u", ['admin']);
不确定
insert failed: MongoError: E11000 duplicate key error index: meteor.roles.$name_1 dup key: { : "admin" }
update failed: Access denied
Roles.addUsersToRoles("Meteor.user()", ['admin']);
undefined
insert failed: MongoError: E11000 duplicate key error index: meteor.roles.$name_1 dup key: { : "admin" }
这似乎表明,这个用户已经有角色分配到它。我期望的权限错误取决于未发布的角色。如果有重复的错误,那么看起来这个用户应该分配给它的管理员角色。
下面是相关的代码。 模板:
<template name="adminTemplate">
{{#if isAdminUser}}
{{> accountsAdmin}}
{{else}}
Must be admin to see this...
{{/if}}
</template>
<template name="accountsAdmin">
accountsAdmin template
</template>
助手:
Template.adminTemplate.helpers({
// check if user is an admin
isAdminUser: function() {
return Roles.userIsInRole(Meteor.user(), ['admin']);
}
})
我router.js文件
Router.configure({
layoutTemplate: 'layout'
});
Router.map(function() {
this.route('home', {path: '/'});
this.route('about', {path: '/about'});
this.route('faq', {path: '/faq'});
this.route('myaccount', {path: '/myaccount'});
this.route('admin', {
layoutTemplate: 'adminlayout',
path:'/admin',
template: 'accountsAdmin',
onBeforeAction: function() {
if (Meteor.loggingIn()) {
this.render(this.loadingTemplate);
} else if(!Roles.userIsInRole(Meteor.user(), ['admin'])) {
console.log('redirecting');
this.redirect('/');
}
}
});
});
我有我的startup.js
Meteor.startup(function() {
// This is temporary
if (Meteor.users.findOne("Nvu2wZRg3K2wd4j4u"))
Roles.addUsersToRoles("Nvu2wZRg3K2wd4j4u", ['admin']);
});
以下任一有人对此有任何想法NE?
这非常谢谢:)我只需要改变“用户名”在insertUsers功能“电子邮件”。现在工作:) – user1532669 2014-09-02 15:30:36