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
|
|
|
|
},
|
2014-08-23 11:28:05 +09:00
|
|
|
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
|
|
|
},
|
2014-08-23 11:53:37 +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
|
|
|
|
}
|
2014-10-06 17:11:43 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_.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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-21 23:07:36 +08:00
|
|
|
Meteor.users.allow({
|
2013-10-31 10:41:01 +09:00
|
|
|
update: function(userId, doc){
|
|
|
|
return isAdminById(userId) || userId == doc._id;
|
|
|
|
},
|
|
|
|
remove: function(userId, doc){
|
|
|
|
return isAdminById(userId) || userId == doc._id;
|
|
|
|
}
|
2013-10-21 23:07:36 +08:00
|
|
|
});
|