![](/img/trans.png)
[英]Where do I put this line of code on the new file structure of Meteor?
[英]Do I need to put createUser code in a meteor method?
我正在編寫一個流星應用程序,並正在處理用戶注冊模板。
當前,我在客戶端上導入了以下代碼:
Template.register.events({
'submit form': function(event){
event.preventDefault();
let username = $('[id=input-username').val();
let email = $('[id=input-email]').val();
let password = $('[id=input-password]').val();
Accounts.createUser({
username: username,
email: email,
password: password
}, function(error){
if(error){
Bert.alert( "That username or email is either taken or invalid. Try again.", 'danger', 'growl-top-right' );
// console.log(error.reason);
}
else {
FlowRouter.go('mainLayout');
}
});
}
});
我的問題是,可以在客戶端上使用Accounts.createUser代碼,還是需要從服務器上導入的流星方法調用此代碼? 在我的腦海中,我認為用戶可以使用不同的電子郵件/用戶名注冊任意多次,因此在客戶端上存儲代碼與調用服務器相比有什么害處?
歡迎思想。
CreateUser
設計為可從客戶端使用。 在將密碼發送到服務器之前,它會處理密碼的加密。
您可以在客戶端進行驗證以節省時間,但是理想情況下,您應該在服務器端的流星方法中編寫代碼,然后通過Meteor.call()在客戶端調用它。 在您的情況下,我可以簡單地使用chrome控制台添加用戶,並且可以將其循環到一百萬次以在數據庫中添加隨機內容。 這種方式最受Csrf攻擊。 定義新的Mongo.Collection()時,還應該指定collections.allow()和collections.deny()。 另外,您應該從流星項目中刪除自動發布和不安全的軟件包。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.