Vulcan/collections/users.js

70 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-05-10 16:57:17 +09:00
var Schema = {};
2015-01-22 12:03:44 +09:00
var userSchemaObject = {
2014-06-22 10:58:02 +09:00
_id: {
type: String,
2014-06-22 17:25:07 +09:00
optional: true
2014-06-22 10:58:02 +09:00
},
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
emails: {
type: [Object]
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: { // public and modifiable
type: Object,
optional: true,
blackbox: true
},
data: { // public but not modifiable
2014-08-05 12:25:26 +09:00
type: Object,
optional: true,
blackbox: true
2014-06-22 10:58:02 +09:00
},
votes: { // used for votes only
type: Object,
optional: true,
blackbox: true
},
2014-06-22 10:58:02 +09:00
services: {
type: Object,
optional: true,
blackbox: true
}
};
_.each(addToUserSchema, function(item){
2015-01-22 12:03:44 +09:00
userSchemaObject[item.propertyName] = item.propertySchema;
2014-05-10 16:57:17 +09:00
});
2015-01-22 12:03:44 +09:00
Schema.User = new SimpleSchema(userSchemaObject);
2014-05-10 16:57:17 +09:00
// Meteor.users.attachSchema(Schema.User);
2014-09-23 11:30:21 +09:00
Meteor.users.deny({
update: function(userId, post, fieldNames) {
if(isAdminById(userId))
return false;
// deny the update if it contains something other than the profile field
2014-09-28 08:46:20 +09:00
return (_.without(fieldNames, 'profile', 'username', 'slug').length > 0);
2014-09-23 11:30:21 +09:00
}
});
Meteor.users.allow({
update: function(userId, doc){
return isAdminById(userId) || userId == doc._id;
},
remove: function(userId, doc){
return isAdminById(userId) || userId == doc._id;
}
});