2016-01-22 53 views
1

我正在尋找具有用戶權限管理和查看應用程序內容訪問權限的解決方案。用戶在流星中的新網站應用程序的訪問管理

我的目標是:

  • 觀點不同的網頁登錄不同的用戶組
  • 我需要通過管理員帳戶來管理這個羣體
  • 那麼Web應用程序會檢查用戶的權利,並準備專門的頁面每個組

我花了一些時間,但無法找到該解決方案的好模塊。並決定創建我自己的管理面板,以及包含用戶權限的集合。

在這一刻我有一個快速的形式的問題,它並沒有告訴我一個值的一半:

Meteor.publish('allUsers',function(){ 
    return Meteor.users.find({}) 
}); 
Meteor.publish('userAcCardS',function(){ 
    return RoleCard.find({userId: this.userId}); 
}); 

<template name="singleUser"> 
    <h1 class="page-title"> user - {{_id}} <i class="fa fa-pencil"></i></h1> 
    <h3> 
    -{{RCList._id}}-{{RCList.name}}-{{RCList.isAdmin}}- 

    {{#if RCList}} 
    {{> quickForm id="update_card" collection="RoleCard" doc=this type="update"}} 
    {{else}} 
    noth {{> quickForm id="new_card" collection="RoleCard" type="insert"}} 
    {{/if}} 
    </h3> 
</template> 

Template.singleUser.onCreated(function() { 
    var self = this; 
    self.autorun(function() { 
    self.subscribe('userAcCardS'); 
    }); 
}); 

Template.singleUser.helpers({ 
    userEmail: function(){ 
    return this.emails\[0\].address; 
    }, 
    RCList: function(){ 
     return RoleCard.findOne({userId: this._id}); 
    } 
}); 

但我只看到這一點:

User Management Meteor

那麼,什麼是錯的?如果你知道它,也許你可以給我建議,以使用另一種解決方案,如流星包?

或者,也許你可以告訴我如何渲染基於「RCList」的autoform,可以提供角色卡集合的更改,如果可能的話?我是流星和js中的嶄新...

回答

0

最受歡迎的角色包是alanning:roles包。它允許您控制用戶角色並根據這些角色限制訪問。使用此命令來安裝它爲您的項目:

流星添加alanning:角色

這裏是它的一個例子是使用限制公佈的數據:

Meteor.publish('secrets', function (group) { 
    if (Roles.userIsInRole(this.userId, ['view-secrets','admin'], group)) { 
     return Meteor.secrets.find({group: group}); 
    } else { 
     // user not authorized. do not publish secrets 
     this.stop(); 
     return; 
    } 
}); 

限制所看到的示例客戶:

<template name="header"> 
    ... regular header stuff 
    {{#if isInRole 'admin'}} 
     {{> admin_nav}} 
    {{/if}} 
    {{#if isInRole 'admin,editor'}} 
     {{> editor_stuff}} 
    {{/if}} 
</template>