2015-05-02 44 views
1

我正在嘗試使用自定義登錄窗體來驗證用戶身份。我設計的形式,我試圖對用戶進行認證這樣的:無法使用電子郵件和密碼進行身份驗證

Template['account.login'].events 
'submit #login-form': (e, t) -> 
e.preventDefault() 

Meteor.loginWithPassword(
    t.find('#login_username').value, 
    t.find('#login_password').value, 
    (err)-> 
    console.log(err) 
) 
return false 

相關模板(玉 - 對不起):

form.smart-form.client-form#login-form(novalidate) 
    fieldset 
     section 
      label.input 
       input#login_username(type="text", name="username") 
     section 
      label.input 
       input#login_password(type="password", name="password") 
    footer 
     button.btn.btn-primary(type="submit", id="login.btn.login") Login 

從我在網上找到的資源,這將是正確的。不過,我得到這個異常拋出的服務器上:

Exception while invoking method 'login' Error: Match error: Failed Match.Where validation in field username in field user.username 
+0

很難說沒有看到模板。嘗試在調用'loginWithPassword'前調用'console.log'值 - 可能其中一個是空的。 –

+0

好的,謝謝,我更新了問題以包含模板代碼。我在控制檯中輸出了值,看起來它們被正確拾取。它可以有什麼關係和隱式的check()方法在參數上調用? – Genu

+0

@Genu,你是如何解決它的?我處於同樣的情況 – securecurve

回答

0

你忘了添加一個標籤,Meteor.loginWithPassword()運行模板事件之外。將您的咖啡代碼粘貼到http://js2.coffee/,您馬上就會看到它。

相關問題