2016-11-27 35 views
0

我有手動添加的超級用戶,並且此用戶可以通過我給他的表單手動通過其他用戶。如何手動添加用戶到Meteor.users集合?

可以說,如果我救如下圖所示的類似的代碼將用戶輸入的輸入:

Session.set('name', t.find('#name').value); 
Session.set('password', t.find('#pass').value); 
Session.set('email', t.find('#email').value); 

我怎麼這些值存儲在Meteor.users這些會議,檢查有沒有賽後在電子郵件和用戶名?

以及如何在將密碼存儲到我的數據庫之前加密密碼?

+0

你爲什麼不能創建一個用戶我的方法,下面給出的ID使用accounts.createUser()流星方法創建服務器端流星調用並創建用戶? –

+0

是的,但是將用戶輸入插入到users.collection中的mongodb代碼是什麼? –

+0

@HafizAllyLalani如果我沒有弄錯,你的意思是我在服務器端實現一個將用戶插入Meteor.users集合的函數?然後在客戶端收集它?我對嗎?請糾正我,如果不是:) –

回答

2

從客戶端的調用時該代碼:

Meteor.call('createUser','[email protected]','password123',function(err,res){ 
    ..... 
}) 

創造了Meteor.users收集用戶在

Meteor.methods({ 
    createUser(email,password){ 
    check(email,String); 
    check(password,String);  
    let id = Accounts.createUser({ 
     email: email, 
     password: password, 
     profile: {} //anything you like to add to profile. 
    })  
    } 
})