Skip to content

Commit

Permalink
add random attribute to user props
Browse files Browse the repository at this point in the history
Allows easier random sampling
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Aug 15, 2015
1 parent f710fa1 commit 13b38ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion common/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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', {
Expand Down
4 changes: 4 additions & 0 deletions common/models/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
}
],
"default": []
},
"rand": {
"type": "number",
"index": true
}
},
"validations": [],
Expand Down
1 change: 1 addition & 0 deletions seed/loopbackMigration.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ var users = dbObservable
user[provider + 'id'] = user[provider];
user[provider] = null;
});
user.rand = Math.random();

return user;
})
Expand Down

0 comments on commit 13b38ae

Please sign in to comment.