【问题标题】:Can't change Accounts.Config after startup of Meteor App启动 Meteor App 后无法更改 Accounts.Config
【发布时间】:2014-08-28 00:29:56
【问题描述】:

在我的 Meteor 应用程序的管理部分,我想使用 USERNAME_AND_OPTIONAL_EMAIL(或 EMAIL_ONLY)为“PowerUser”调用 Account.CreateUser(..),然后使用 sendVerificationEmail,这很好用......

Accounts.config(sendVerificationEmail: true);

但接下来我还想使用 USERNAME_ONLY 而不是 sendVerificationEmail 为“LocalUser”调用 Account.CreateUser(..),因为本地用户帐户不需要电子邮件。

Accounts.config(sendVerificationEmail: false);

当我第二次调用 Accounts.config 时,我的问题是“错误:不能多次设置 sendVerificationEmail”。

【问题讨论】:

    标签: meteor accounts


    【解决方案1】:

    我发现配置为 USERNAME_AND_OPTIONAL_EMAIL 对于这两种情况都足够了:

    客户端上的一次性配置:

    Accounts.ui.config({ passwordSignupFields: 'USERNAME_AND_OPTIONAL_EMAIL' });

    服务器上的一次性配置:

    Accounts.config({
        sendVerificationEmail: true, 
        forbidClientAccountCreation: true
    })
    

    然后创建“LocalUser”的代码提供用户名和初始密码

      var newUserId = Accounts.createUser({
            username: username,
            password: 'pw_for_' + username,
            profile: {
              name: name,
              company: company
            }
          }); 
    

    并为管理员提供这些值以与新的 LocalUser 进行通信,以便他们可以登录。由于没有电子邮件,因此不需要发送验证电子邮件。

    然后代码创建超级用户,提供电子邮件(可选用户名)和密码:

       var newUserId = Accounts.createUser({
            email: email,
            profile: {
              name: name,
              company: company
            }
          }); 
    

    然后我们发送注册电子邮件,以便 PowerUser 收到设置初始密码的链接:

    var enroll = Accounts.sendEnrollmentEmail(newUserId);
    

    就是这样!

    【讨论】:

    • 你在哪里设置 Accounts.config ?
    猜你喜欢
    • 2017-12-10
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多