繁体   English   中英

流星Js限制对我的流星应用程序的访问

[英]Meteor Js limiting access to my meteor app

我有一个流星应用程序,我想托管它,但是我只希望几个人登录并可以访问它,最多5个人。 我该怎么做?

您可以创建5个这样的帐户:

 Meteor.startup(function () {
   if (Meteor.users.find().count() === 0) {
     Accounts.createUser({
        username: 'xxxxx',
        email: 'xxxx@xxxx.xx',
        password: 'xxxxxxx',
        profile: {}
     });
    ...
   }
 });

并避免创建新用户的可能性:

AccountsTemplates.configure({
     forbidClientAccountCreation: true,
 });

您可以使用以下方法阻止创建新用户:

Accounts.config({ forbidClientAccountCreation : true });

在重新启动应用程序时检查Meteor.startup的用户Meteor.startup将阻止创建用户,并且已经创建了5个用户。

创建5个用户后,您可以在Accounts.onCreateUser引发错误。 每次要创建新用户时,都会调用onCreateUser。 引发错误将取消用户创建。

if (Meteor.isServer) {
  Meteor.startup(function () {
       if (Meteor.users.find().count() >= 5)
          Accounts.config({
              forbidClientAccountCreation : true
          });
  });

  Accounts.onCreateUser(function (options, user) {
     var numberOfUsers = Meteor.users.find().count();
     if (numberOfUsers >= 4) {
         Accounts.config({
             forbidClientAccountCreation : true
         });
     };
     if (numberOfUsers >= 5) 
       throw new Meteor.Error(403, "Signup forbidden");
     return user;
  });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM