2014-01-17 78 views
2

我試圖創建多個用戶,所以我做的「創建用戶」使用Accounts.createUser樣本的例子。我還添加了一個包accounts-baseaccounts-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. 
     } 
    }); 
} 

回答

2

的問題是在這兩條線

var email = document.getElementById('email'); 
var password = document.getElementById('pwd'); 

getElementById僅返回一個參考元件,而不是值。

改變他們

var email = document.getElementById('email').value; 
var password = document.getElementById('pwd').value; 
+0

在你成功告訴它的作品之後改變之後,謝謝你。@ Tobold。 – Venkat

+4

很高興我能幫到你。如果通過點擊旁邊的複選標記解決問題,您可以接受我的答案。 – Tobold

+0

我試圖在這個時候,我得到這個錯誤即未捕獲的錯誤,以創建多個用戶:必須設置options.password所以,我可以爲這個問題做也改變後我的代碼,請檢查一次也@ Tobold。 – Venkat

-2

您必須添加帳戶 - 基礎包項目。

+0

是啊,我添加帳戶 - 基礎包,即使從同樣的錯誤受到影響。@維吾爾族Toprakdeviren – Venkat

+1

真實的,但'當添加'賬戶,base'自動添加帳戶,password' – Tobold

相關問題