【问题标题】:How to delete users from account-ui meteor如何从account-ui meteor中删除用户
【发布时间】:2015-07-05 21:56:26
【问题描述】:

我正在制作一个流星应用程序并使用帐户 ui 和 bootstrap 以及所有这些东西,但我想知道是否有一种方法可以让我像管理员一样删除用户,因为最近人们一直在使用不适当的用户名等。 .

【问题讨论】:

    标签: meteor


    【解决方案1】:

    你可以很容易地删除用户。拥有一个仅受 admin accounts 保护的模板,并在该模板上有一个用户列表,基于该列表创建这样的事件。

    Template.example.events({
     'click #deleteAccount':function(){
        meteor.users.remove({_id:this._id}) 
      }
    })
    

    并使用这样的允许方法。

    Meteor.allow({
     remove:function(){
       //if is admin return true;
      }
    })
    

    但这不是一个好习惯,为什么?检查这个David Weldon -common-mistakes

    如果有办法让我成为管理员?

    为了以更好的方式完成此操作,请使用meteor-roles package

    有了这个,你可以保护模板

    {{if isInRole 'Admin'}}
     <!--show admin stuff-->
       {{else}}
     <!--sorry just admin stuff here -->
    {{/else}}
    

    并创建基本管理员帐户。

    if(Meteor.users.find().count() === 0){
      var users = [
          {name:"Admin Example",email:"supersecretaccount@gmail.com",roles:['Admin']}
        ];
    
      _.each(users, function (user) {
        var id;
    
        id = Accounts.createUser({
          email: user.email,
          password: "amore251327",
          profile: { name: user.name }
        });
    
        if (user.roles.length > 0) {
          Roles.addUsersToRoles(id, user.roles);
        }
    
      });  
    }
    

    试试看

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多