2015-09-26 39 views
3

Meteor的默認設置不允許從客戶端創建帳戶,這對於許多應用程序中的安全目的而言是有意義的,但我正在構建博客,並且需要允許用戶創建帳戶以便他們留下評論。如何在Meteor中將forbidClientAccountCreation設置爲false?

在github上,計算器,以及各種教程典型的反應似乎暗示添加以下代碼到你的文件,外面的客戶機/服務器的條件句的任何地方,以便它可以在客戶端和服務器上運行:

Accounts.config({ 
    forbidClientAccountCreation: false 
}); 

似乎很簡單。我在lib文件夾進入這段代碼在一個文件中(configure.js),但出現在終端中輸入以下錯誤消息:

W20150925-19:52:17.568(9)? (STDERR) /Users/Eric/.meteor/packages/meteor-tool/.1.1.4.2l3p0l++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245 
W20150925-19:52:17.568(9)? (STDERR)       throw(ex); 
W20150925-19:52:17.568(9)? (STDERR)        ^
W20150925-19:52:17.627(9)? (STDERR) Error: Can't set `forbidClientAccountCreation` more than once 
W20150925-19:52:17.627(9)? (STDERR)  at packages/accounts-base/accounts_common.js:95:1 
W20150925-19:52:17.627(9)? (STDERR)  at Array.forEach (native) 
W20150925-19:52:17.627(9)? (STDERR)  at Function._.each._.forEach (packages/underscore/underscore.js:105:1) 
W20150925-19:52:17.628(9)? (STDERR)  at Object.Accounts.config (packages/accounts-base/accounts_common.js:92:1) 
W20150925-19:52:17.628(9)? (STDERR)  at app/lib/configure.js:1:45 
W20150925-19:52:17.628(9)? (STDERR)  at app/lib/configure.js:5:3 
W20150925-19:52:17.628(9)? (STDERR)  at /Users/Eric/pilgrim/.meteor/local/build/programs/server/boot.js:222:10 
W20150925-19:52:17.628(9)? (STDERR)  at Array.forEach (native) 
W20150925-19:52:17.628(9)? (STDERR)  at Function._.each._.forEach (/Users/Eric/.meteor/packages/meteor-tool/.1.1.4.2l3p0l++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) 
W20150925-19:52:17.628(9)? (STDERR)  at /Users/Eric/pilgrim/.meteor/local/build/programs/server/boot.js:117:5 
=> Exited with code: 8 
=> Your application is crashing. Waiting for file change. 

行「不能設置比一次更forbidClientAccountCreation」似乎意味着問題源於多個軟件包以某種方式重新確定相同的代碼。我有一些軟件包,如帳戶用戶界面,帳戶密碼,useraccounts:核心和useraccounts:基礎,但它似乎流星得到了衝突信號(其他人抱怨與useraccounts衝突:bootstrap作爲)我不確定這些代碼是否是我的代碼中的直接衝突源,其他開發人員建議刪除任何衝突的軟件包,但這似乎是一個糟糕的解決方案。這些軟件包是有原因添加的。應該有一種方法可以明確地設置這個變量而沒有問題。

我似乎無法找到合理的解決方案。思考?

回答

1

流星確實允許從客戶端創建帳戶。

最好想想如何根據您添加和/或刪除的軟件包以及編寫哪些代碼塊(服務器/客戶端)來設置項目。

瞭解您添加/刪除了哪些軟件包是關於如何從客戶端和/或服務器創建用戶的基本因素。

您使用哪個軟件包來創建用戶?

以下是使用accounts-password包從客戶端創建用戶的一個簡單示例。用戶在此提供的憑據是電子郵件地址和密碼。請注意,還有用於創建用戶的外部程序包。

第一:

meteor remove insecure 
meteor add accounts-password 

HTML:

<body> 
    {{> join}} 
</body> 

<template name="join"> 
    <input type="email" id="email"> 
    <input type="password" id="password" placeholder="6 charactors minimum"> 
    <button class="submit"></button> 
</template> 

JS:

Template.join.events({ 
    'click .submit': function(e, template) { 
    var email = template.find('#email').value; 
    var password = template.find('#password').value; 

     Accounts.createUser({ 
      email: email, 
      password: password 
     }, 
     function(error) { 
      if (error) { 
       console.log(error); 
      } 
      else { 
       console.log("account created"); 
      } 
     }); 
    } 
}); 

打開蒙戈外殼並鍵入db.users.find(),你會看到所創建的用戶。

未來,最好提出一個問題,提供更多詳細信息,使SO社區能夠重現代碼/問題以及解決方案。

+0

我刪除不安全和即時通訊仍然能夠使用accounts-ui帳戶? –

2

使用useraccounts:core程序包時,不能將其設置爲false,因爲該程序包將其設置爲true。 useraccounts套件提供了一個應允許用戶默認創建帳戶的界面。在使用useraccounts套件時,您不能使用accounts-ui提供的UI創建用戶(也不能在客戶端上使用Accounts.createUser())。

相關問題