我已经被这个问题困扰了一天半了。我要做的是在我的 Meteor.User 集合中创建一个 userProfile 部分。因此,当用户登陆“设置”页面时,他们可以更新他们的信息。这就是我所拥有的。
顺便说一句,我正在使用用户帐户包进行登录/注册过程。
更新:3 表单提交但没有数据被插入/更新。我已经注释掉了“Schema.User”,因为如果我将它放入并将其附加到 Meteor.users.attachSchema(Schema.User)。自动表单加载字段。这就是为什么我把 Schema.UserProfile 改为。我检查了控制台日志,它给了我错误“[Access Denied] 403”它一定是允许/拒绝冲突吗?我在这里列出了所有代码。
设置 HTML:
<template name="settings">
<div class="text-center light-container" id="settings-section">
{{> quickForm collection="Meteor.users" doc=currentUser id="userProfile" type="update"}}
</div>
在两个目录中设置 JS
Schema = {};
Schema.UserProfile = new SimpleSchema({
userProfile: {
type: Object
},
'userProfile.firstName':{
type: String,
label: "First Name",
max: 80
},
'userProfile.lastName':{
type: String,
label: "Last Name",
max: 80
},
'userProfile.gender':{
type: String,
label: "Gender",
allowedValues: ["Male", "Female"]
},
'userProfile.birthday':{
type: Date,
label: "Date Of Birth",
autoform: {
type: "bootstrap-datepicker"
}
},
address:{
type: Object
},
'address.city':{
type: String,
label: "City/Province",
max: 80
},
'address.state':{
type: String,
label: "State",
max: 80
},
'address.country':{
type: String,
label: "Country",
max: 80
},
/*privacy:{
type: String,
label: "Privacy",
allowedValues: ["On", "Off"]
}, */
aboutYou:{
type: String,
label: "About You",
autoform: {
afFieldInput: {
type: "textarea"
}
},
max: 400
},
socialNetworks:{
type: Object,
label: "Social Networks"
},
'socialNetworks.facebook':{
type: String,
label: "Facebook",
autoform: {
placeholder: 'Username'
},
max: 50
},
'socialNetworks.instagram':{
type: String,
label: "Instagram",
autoform: {
placeholder: 'Username'
},
max: 50
},
'socialNetworks.tumblr':{
type: String,
label: "Tumblr",
autoform: {
placeholder: 'Username'
},
max: 50
},
'socialNetworks.twitter':{
type: String,
label: "Twitter",
autoform: {
placeholder: 'Username'
},
max: 50
}
});
/*
Schema.User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/,
optional: true
},
emails: {
type: [Object],
// this must be optional if you also use other login services like facebook,
// but if you use only accounts-password, then it can be required
optional: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: {
type: Schema.UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true
}/*,
// 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
}
*/
});
*/
Meteor.users.attachSchema(Schema.UserProfile);
Meteor.users.allow({
insert: function(userId, doc) {
// only allow posting if you are logged in
console.log("doc: " + doc + " userId: " + userId);
return !! userId;
},
update: function(userId, doc) {
// only allow updating if you are logged in
console.log("doc: " + doc + " userId: " + userId);
return !! userId;
},
remove: function(userID, doc) {
//only allow deleting if you are owner
return doc.submittedById === Meteor.userId();
}
});
在客户端目录中设置 JS
/*
var postHooks = {
before: {
insert: function(doc) {
if(Meteor.userId()){
doc.userId = Meteor.userId();
}
return doc;
}
},
docToForm: function(doc) {
if (_.isArray(doc.tags)) {
doc.tags = doc.tags.join(", ");
}
return doc;
},
formToDoc: function(doc) {
if (typeof doc.tags === "string") {
doc.tags = doc.tags.split(",");
}
return doc;
}
};
AutoForm.addHooks('UserProfile', postHooks);
*/
如果有人能指出我正确的方向,那将非常有帮助!