2015-05-07 56 views
1

使用simple schemaaccounts-password。我試圖在啓動時添加一個初始帳戶,但電子郵件和密碼未顯示。流星用戶沒有電子郵件地址

Schemas.User = new SimpleSchema({ 
    username: { 
    type: String, 
    regEx: /^[a-z0-9A-Z_]{3,15}$/ 
    }, 
    emails: { 
    type: [Object], 
    optional: true 
    }, 
    "emails.$.address": { 
    type: String, 
    regEx: SimpleSchema.RegEx.Email 
    }, 
    "emails.$.verified": { 
    type: Boolean 
    }, 
    profile: { 
    type: Schemas.UserProfile, 
    optional: true 
    } 
}); 

Meteor.startup(function() { 
    Meteor.users.remove({}); 
    if (Meteor.users.find().count() == 0) { 
    Accounts.createUser({ 
     username: "newuser", 
     emails: [{address:"[email protected]", verified:true}], 
     password:"mypassword" 
    }); 
    } 
    console.log(Meteor.users.find().fetch()); 
} 

給我們:

[{_id: 'xxx', username:'newuser'}] 

沒有電子郵件或密碼。沒有錯誤。思考?

此係統中的新用戶只能由現有用戶添加,因此我無法測試用戶提交表單。

+0

[Accounts.createUser](http://docs.meteor.com/#/full/accounts_createuser)將「String」作爲第二個參數,而不是數組。只需將它作爲一個字符串給它,然後再驗證它。 – SylvainB

+0

對不起,參數''電子郵件'屬性的'選項'參數 – SylvainB

+0

@BraveKenny電子郵件的工作,但現在我得到「沒有密碼設置」錯誤嘗試登錄 –

回答

2

Accounts.createUseroptions參數的字符串作爲email屬性。至於密碼問題,可能是由於架構中缺少services屬性。添加到您的Schemas.User以下屬性:

Schemas.User = new SimpleSchema({ 
    // ... 
    services: { 
     type: Object, 
     optional: true, 
     blackbox: true 
    } 
} 

最後,Accounts.createUser文檔(參見第一個鏈接)規定:

On the client, you must pass password and at least one of username or email — enough information for the user to be able to log in again later. On the server, you do not need to specify password, but the user will not be able to log in until it has a password (eg, set with Accounts.setPassword).

它似乎不是在你的情況下適用,但作爲最後的手段,嘗試事後致電Accounts.setPassword(userId, "mypassword")。用戶的ID由Meteor.createUser返回。

+0

錯誤:services.password.srp是模式不允許 –

+0

更新了我的答案 – SylvainB