我試圖創建多個用戶,所以我做的「創建用戶」使用Accounts.createUser
樣本的例子。我還添加了一個包accounts-base
和accounts-password
。但是我得到了一個錯誤Must set options.password in Meteor
。我不知道發生了什麼事。請查看下面的代碼。未捕獲的錯誤:必須設置options.password流星
只有點擊註冊按鈕,在那個時候,我得到了錯誤
HTML:
<head>
<title>loginapp</title>
</head>
<body>
{{> main}}
</body>
<template name="main">
<form id="login-form" action="action">
<div>
<h2>Login<h2>
<input type="text" id="email" placeholder="Email" /><br>
<input type="password" id="pwd" placeholder="Password" /><br>
<input type="submit" value="Login" id="login" />
</div>
</form>
<form id="register-form" action="action">
<div>
<h2> Create Account<h2>
<input type="text" id="username" placeholder="Enter UserName" /><br>
<input type="text" id="name" placeholder=" Enter Name" /><br>
<input type="text" id="email" placeholder=" Enter Email" /><br>
<input type="password" id="pwd" placeholder=" Enter Password" /><br>
<input type="submit" value="Register" id="register" />
</div>
</form>
</template>
的Javascript:
if (Meteor.isClient) {
Template.main.events({
'submit #login-form': function (e, t) {
// template data, if any, is available in 'this'
console.log("You pressed the button LOGIN ");
e.preventDefault();
// retrieve the input field values
var email = t.find('#email').value
, password = t.find('#pwd').value;
console.log(email);
Meteor.loginWithPassword(email, password, function (err) {
if (err) {
console.log(err);
Session.set("loginError", true);
} else {
console.log(" Login Success ");
}
});
}
});
Template.main.events
({
'submit #register-form': function (e, t) {
console.log("You pressed the button Register ");
e.preventDefault();
var username = t.find('#username').value
, name = t.find('#name').value
, email = t.find('#email').value
, password = t.find('#pwd').value;
Accounts.createUser({email: email, password: password, username: username, }, function (err) {
if (err) {
console.log(err);
}
else {
console.log("Register Successfully");
}
});
}
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
if (Meteor.users.find().count() === 0) {
Accounts.createUser
({
username: 'username',
email: '[email protected]',
password: '123456',
profile: {
first_name: 'fname',
last_name: 'lname',
company: 'CubeTech',
}
}) //Added close parenthesis.
}
});
}
在你成功告訴它的作品之後改變之後,謝謝你。@ Tobold。 – Venkat
很高興我能幫到你。如果通過點擊旁邊的複選標記解決問題,您可以接受我的答案。 – Tobold
我試圖在這個時候,我得到這個錯誤即未捕獲的錯誤,以創建多個用戶:必須設置options.password所以,我可以爲這個問題做也改變後我的代碼,請檢查一次也@ Tobold。 – Venkat