2016-07-22 100 views
0

我想用reactmeteor我已經建立了建立一個管理認證使用React客戶端文件夾內登錄表格如下:流星反應的管理設置

class Admin extends Component { 

    onSubmit(event) { 
    event.preventDefault(); 

    const self = this; 
    const email = $(event.target).find('[name=email]').val(); 
    const password = $(event.target).find('[name=password]').val(); 

    Meteor.loginWithPassword(email, password, function (err) { 
     if (err) console.log(err.reason); 
    }); 
    } 

    render() { 
    return (
     <div className='flex-login'> 
     <form onSubmit={this.onSubmit}> 
      <div className='login'> 
      <div className='welcome'> 
       <p><strong>Greetings</strong>, my dear master :) </p> 
       <p>Did anything surprise you today?</p> 
      </div> 
      <input name='email' type="email" placeholder="Name" /> 
      <input name='password' type="password" placeholder="Secretword" /> 
      <button type="submit">Enter</button> 
      </div> 
     </form> 
     </div> 
    ); 
    } 
} 

並增加以下Accounts.createUser到服務器main.js文件:

import { Meteor } from 'meteor/meteor'; 
import { Accounts } from 'meteor/accounts-base'; 

// Creating user 
Meteor.startup(() => { 
    if (Meteor.users.find().count === 0) { 
    Accounts.createUser({ 
     email: '[email protected]', 
     password: 'master' 
    }); 
    } 
}); 

當我嘗試使用定義的帳戶信息登錄我收到的console.log User not found

你能解釋一下我失蹤以達到結果嗎?

如果您可以向我解釋我或向我指出某些外部資源,我也會非常感激,如何爲管理員定製安全登錄以便使其保存在production version中。

這些身份驗證的目的是允許進一步訪問管理集合的信息。

回答

0

您使用計數代替Meteor.users.find()計數()。COUNT()

+0

你是對的,是個問題。現在它可以工作,非常感謝你。你能解釋一下,在生產版本中,流星應用的服務器端是否有管理員賬號信息? – volna

+0

我不明白你的意思。請你說明你想達到什麼目的? –

+0

我想建立自定義的管理面板,所以我需要定義管理帳戶,以便使用Meteor.userID()在管理頁面進行進一步的身份驗證和驗證; – volna

0

我認爲管理員沒有被創建,因爲有其他用戶,Meteor.users.find().count()的值永遠不會爲零。您應該檢查角色爲「admin」的用戶是否爲零並創建管理員。您可以使用角色包alanning:roles向用戶添加角色。

希望它可以幫助

感謝

+0

謝謝你的建議khem,其實當我鍵入到控制檯Meteor.users.find()。count()我收到0 :) – volna

+0

使用計數()它的一個方法,你正在使用計數meteor.users.find()。count() –