繁体   English   中英

如何添加自己的Meteor.users个人资料; 使用aldeed autoform和collection2

[英]How to make my own Meteor.users profile additions; using aldeed autoform and collection2

我是流星,正在编码新手。 我整天都在尝试使用aldeed:autoform和aldeed:collection2将配置文件信息添加到Meteor.users。 我的成功参差不齐,我几乎得到了想要的东西(发布到mongo,但是创建了新的id而不是附加到当前的id),但是却迷失了自己。 现在,我不断

SimpleSchema invalid keys ... 0: Object
name: "emails"
type: "expectedArray"

而且我“提交”的任何内容都不会发布到Mongo。

这是我认为我需要的所有东西:collections / simpleSchema.js

Meteor.users.allow({
    update: function (userId, doc){
        return !!userId;
    }
});


Schema.UserProfile = new SimpleSchema({
    firstName: {
        type: String,
        optional: true
    },
    lastName: {
        type: String,
        optional: true
    },
    birthday: {
        type: Date,
        optional: true
    },
    grade: {
        type: String,
        allowedValues: ['5', '6', '7', '8'],
        optional: true
    }
});

Schema.User = new SimpleSchema({        
    username: {
        type: String,
        // For accounts-password, either emails or username is required, but not both. It is OK to make this
        // optional here because the accounts-password package does its own validation.
        // Third-party login packages may not require either. Adjust this schema as necessary for your usage.
        optional: true,
        autoform: {
            type: "hidden"
        }
    },
    emails: {
        type: Array,
        // For accounts-password, either emails or username is required, but not both. It is OK to make this
        // optional here because the accounts-password package does its own validation.
        // Third-party login packages may not require either. Adjust this schema as necessary for your usage.
        optional: true,
        autoform: {
            type: "hidden"
        }
    },
    "emails.$": {
        type: Object,
        autoform: {
            type: "hidden"
        }
    },
    "emails.$.address": {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
        autoform: {
            type: "hidden"
        }
    },
//    "emails.$.verified": {
//        type: Boolean
//    },
    createdAt: {
        type: Date,
        optional: true,
        autoValue: function(){
            return new Date();
        },
        autoform: {
            type: "hidden"
        }
    },
    profile: {
        type: Schema.UserProfile,
        optional: true
    },
    // Make sure this services field is in your schema if you're using any of the accounts packages
    services: {
        type: Object,
        optional: true,
        blackbox: true,
        autoform: {
            type: "hidden"
        }
    }
    // Add `roles` to your schema if you use the meteor-roles package.
    // Option 1: Object type
    // If you specify that type as Object, you must also specify the
    // `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
    // Example:
    // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
    // You can't mix and match adding with and without a group since
    // you will fail validation in some cases.
    //roles: {
    //    type: Object,
    //    optional: true,
    //    blackbox: true
    //}
    // Option 2: [String] type
    // If you are sure you will never need to use role groups, then
    // you can specify [String] as the type
//    roles: {
//        type: [String],
//        optional: true
//    }
});

Meteor.users.attachSchema(Schema.User);

client.js

SimpleSchema.debug = true

Template.NewUser.helpers({
  updateUserForm: function(){
    return Meteor.user;
  }
});

server.js

Meteor.methods({
 update: function(doc) {
   // Important server-side check for security and data integrity
   check(doc, Meteor.users);
    Meteor.users.clean(doc);
 }
});

感谢您的阅读!

您没有在内容中包含html。 但是,似乎您正在使用自动窗体上的方法更新。 为了使它在您的服务器中工作,您需要调用Meteor.user.update()运算符。

 updateProfile: function(doc, doc_id) { var theUser = Meteor.users.findOne({ _id: doc_id }); if (theUser._id !== Meteor.userId()) { throw new Meteor.Error("Not Authorised"); } else { Meteor.users.update({ _id: doc_id }, doc); } }, 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM