2016-02-05 3 views
2

Я работаю над расширением схемы Meteor.users, которая работает нормально, но после того, как я создал первого пользователя в Meteor.startup() и попытался войти в систему, я получил ошибку «Пользователь не найден» , Хотя я могу видеть пользователя в оболочке mongo. Вот моя схема:Ошибка Meteor: Пользователь не найден

Schemas.User = new SimpleSchema({ 
    username: { 
     type: String, 
     optional: true 
    }, 
    emails: { 
     type: Array, 
     optional: true 
    }, 
    "emails.$": { 
     type: Object 
    }, 
    "emails.$.address": { 
     type: String, 
     regEx: SimpleSchema.RegEx.Email 
    }, 
    "emails.$.verified": { 
     type: Boolean 
    }, 
    createdAt: { 
     type: Date, 
     optional: true 
    }, 
    "firstName":{ 
    type: String, 
    max: 50, 
    min:2 
    }, 
    'middleName':{ 
    type: String, 
    optional: true, 
    max: 50 
    }, 
    "lastName":{ 
    type: String, 
    max: 50, 
    min:2 
    }, 
    "gender": { 
    type: String, 
    autoform: { 
     afFieldInput: {type: "select-radio-inline",}, 
     options: 
     [ 
     {label: "Male", value: "Male"}, 
     {label: "Female", value: "Female"} 

     ] 
    } 
    }, 
    "branch": { 
     type: String, 
     optional: true, 
     autoform: { 
     type: "select", 
     options: function() { 
      return CompanyBranches.find().map(function (c) { 
       return {label: c.companyName+' - '+c.addressCity, value: c._id}; 
      }); 
     } 
    } 
    }, 
    "active":{ 
    type: String, 
    allowedValues: ["Yes","No"], 
    autoform: { 
     options: [ 
     {label: "Yes", value: "Yes"}, 
     {label: "No", value: "No"} 
     ], 
     afFieldInput: { 
     type: "select-radio-inline" 
     } 
    } 
    }, 
    services: { 
     type: Object, 
     optional: true, 
     blackbox: true 
    }, 
    roles: { 
     type: [String], 
     optional: true, 
     autoform: { 
      options: [ 
      {label: "Dashboard", value: "Dashboard"}, 
      {label: "Branches", value: "Branches"}, 
      {label: "User Profile", value: "User Profile"}, 
      {label: "Case Managers", value: "Case Managers"}, 
      {label: "Insurance Company", value: "Insurance Company"}, 
      {label: "Tasks", value: "Tasks"}, 
      {label: "Calendar", value: "Calendar"}, 
      {label: "Contacts", value: "Contacts"}, 
      {label: "Cases", value: "Cases"}, 
      {label: "Requests", value: "Requests"}, 
      {label: "Accounts", value: "Accounts"}, 
      {label: "Reports", value: "Reports"}, 
      {label: "Search", value: "Search"}, 
      {label: "HR", value: "HR"} 
      ], 
      afFieldInput: { 
      type: "select-checkbox-inline" 
      } 
     } 
    } 
    }); 

    Meteor.users.attachSchema(Schemas.User); 

Это моя функция Метеор запуска:

Meteor.startup(function() { 
if (Meteor.users.find().count() === 0) { 
    Accounts.createUser({ 
     username: "[email protected]", 
     email:"[email protected]", 
     password: "leoten", 
     firstName: "Leocrawf", 
     lastName: "Stewart", 
     gender:"Male", 
     active: "Yes" 
     }, function (error) { 
     if (error) { 
      console.log("Cannot create user"); 
     } 
     }); 

    } 
}); 

на сервере я делаю это в Accounts.onCreateUser():

Accounts.onCreateUser(function(options, user) { 
     user = options || {}; 
     user.username = options.username; 
     user.firstName = options.firstName; 
     user.lastName = options.lastName; 
     user.active = options.active; 
     user.gender = options.gender; 
     // Returns the user object 
     return user; 
    }); 

Когда я запрос mongo shell я получаю это:

meteor:PRIMARY> db.users.find().pretty() 
{ 
"_id" : "pFurR8iDYWJcX9rus", 
"username" : "[email protected]", 
"firstName" : "Leocrawf", 
"lastName" : "Stewart", 
"gender" : "Male", 
"active" : "Yes", 
"services" : { 
    "resume" : { 
    "loginTokens" : [ 
      { 
    "when" : ISODate("2016-02-05T23:13:38.364Z"), 
    "hashedToken" : "vs5xVlKL59yVTO/fbKbSnar38I8ILAruj2W1YecQ2Io=" 
      } 
     ] 
    } 
    } 
} 
+0

Мне нужно запомнить документы, 'профиль' не' options' ... –

ответ

1

Это не выглядит, как вы настраиваете профиль правильно при создании пользователя:

Вместо:

Accounts.createUser({ 
    username: "[email protected]", 
    email:"[email protected]", 
    password: "leoten", 
    firstName: "Leocrawf", 
    lastName: "Stewart", 
    gender:"Male", 
    active: "Yes" 
}, 

Try:

Accounts.createUser({ 
    username: "[email protected]", 
    email: "[email protected]", 
    password: "leoten", 
    profile: { 
    firstName: "Leocrawf", 
    lastName: "Stewart", 
    gender: "Male", 
    active: "Yes" 
    } 
}, 

Также рекомендую active: true вместо active: "Yes" для использования булевых строк вместо строки. Это не похоже на то, что вы определили active или gender в вашей схеме либо кстати.

+0

Спасибо за ваш ответ. Я пробовал это, но получил это: options.password должен быть строкой. Я никогда не видел другого примера, когда эти свойства были привязаны к объекту options. – jessiPP

+0

Профайл, мои извинения. Хотя я все время смотрю на все это, я не уверен, что это основная причина вашей проблемы. –

Смежные вопросы