2015-04-05 23 views
2

我正在使用accounts-password package - Meteor。Meteor .. accounts-密碼 - 在沒有登錄的情況下在客戶端上創建帳戶

我爲admin的代碼界面。

管理員將爲其他用戶創建帳戶。

Accounts.createUser({ 
     email: "[email protected]", 
     password : "abc123", 
     profile: { name: register_name } 
    }); 

但這個代碼執行後,我的應用程序自動登錄的帳戶與[email protected],至極我不希望它

問題

如何創建帳戶而不自動登錄?

我讀accounts-password源,但我不知道如何刪除自動登錄

我還試圖用Meteor.users.insert功能,但Accounts.setPassword沒有工作..

回答

2

這是使用一種正常的行爲帳戶包,以避免弄亂源代碼使用Meteor.method/Meteor.call

這是一個簡單的例子,你也可以使用默認的username提交,而不是profile:{name:register_name}

if(Meteor.isServer){ 
     Meteor.methods({ 
      createUserFromAdmin:function(emai,password,username){ 
      Accounts.createUser({email:email,password:password,username:username}) 
     } 
    }) 
    }else if(Meteor.isClient){ 
     Template.admin.events({ 
     'click #createAccount':function(){ 
      Meteor.call('createUserFromAdmin',email,password,username,function(err,result){ 
       if(!err){ 
       console.log("a new user just got created") 
       }else{ 
        console.log("something goes wrong with the following error message " +err.reason) 
       } 
      }) 
      } 
     }) 
     } 

有了這個,你可以在管理模板創建多個帳戶,並繼續在註冊模板自動登錄的行爲(如果有的話)

+0

太謝謝你了! ^^ – Ramacoto 2015-04-05 08:10:36

+1

我對使用這種方法很感興趣,但是在純文本中通過電線發送密碼時有問題嗎?因爲這是你在調用服務器端Meteor方法來創建帳戶時所做的。 – nearpoint 2015-06-08 15:54:26

+0

@nearpoint它不會通過電線發送密碼,因爲Meteor方法'createUserFromAdmin'被封裝在isClient中,所以它只發生在客戶端。 – williamli 2016-10-26 11:33:09

相關問題