add random attribute to user props

Allows easier random sampling
This commit is contained in:
Berkeley Martinez
2015-08-15 12:19:36 -07:00
parent f710fa1af6
commit 13b38aefb5
3 changed files with 11 additions and 1 deletions

View File

@ -7,7 +7,7 @@ import { saveUser, observeMethod } from '../../server/utils/rx';
import { blacklistedUsernames } from '../../server/utils/constants';
const debug = debugFactory('freecc:user:remote');
const BROWNIEPOINTS_TIMEOUT = [30, 'seconds'];
const BROWNIEPOINTS_TIMEOUT = [1, 'hour'];
function getAboutProfile({
username,
@ -35,6 +35,11 @@ module.exports = function(User) {
delete User.validations.email;
// set salt factor for passwords
User.settings.saltWorkFactor = 5;
// set user.rand to random number
User.definition.rawProperties.updated.default =
User.definition.properties.updated.default = function() {
return Math.random();
};
// username should not be in blacklist
User.validatesExclusionOf('username', {

View File

@ -152,6 +152,10 @@
}
],
"default": []
},
"rand": {
"type": "number",
"index": true
}
},
"validations": [],

View File

@ -124,6 +124,7 @@ var users = dbObservable
user[provider + 'id'] = user[provider];
user[provider] = null;
});
user.rand = Math.random();
return user;
})