2015-05-06 12:28:00 +09:00
|
|
|
|
/**
|
|
|
|
|
* Set up user object on creation
|
|
|
|
|
* @param {Object} user – the user object being iterated on and returned
|
|
|
|
|
* @param {Object} options – user options
|
|
|
|
|
*/
|
|
|
|
|
function setupUser (user, options) {
|
|
|
|
|
// ------------------------------ Properties ------------------------------ //
|
|
|
|
|
|
|
|
|
|
var userProperties = {
|
|
|
|
|
profile: options.profile || {},
|
|
|
|
|
telescope: {
|
|
|
|
|
karma: 0,
|
|
|
|
|
isInvited: false,
|
|
|
|
|
postCount: 0,
|
|
|
|
|
commentCount: 0,
|
|
|
|
|
invitedCount: 0,
|
|
|
|
|
upvotedPosts: [],
|
|
|
|
|
downvotedPosts: [],
|
|
|
|
|
upvotedComments: [],
|
|
|
|
|
downvotedComments: []
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
user = _.extend(user, userProperties);
|
|
|
|
|
|
|
|
|
|
// set email on profile, and use it to generate email hash
|
|
|
|
|
if (options.email) {
|
|
|
|
|
user.telescope.email = options.email;
|
|
|
|
|
user.telescope.emailHash = Gravatar.hash(options.email);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 16:18:07 +09:00
|
|
|
|
// set displayName on telescope
|
|
|
|
|
user.telescope.displayName = user.username;
|
2015-05-06 12:28:00 +09:00
|
|
|
|
|
|
|
|
|
// create slug from username
|
|
|
|
|
user.telescope.slug = Telescope.utils.slugify(user.telescope.username);
|
|
|
|
|
|
|
|
|
|
// if this is not a dummy account, and is the first user ever, make them an admin
|
|
|
|
|
user.isAdmin = (!user.profile.isDummy && Meteor.users.find({'profile.isDummy': {$ne: true}}).count() === 0) ? true : false;
|
|
|
|
|
|
|
|
|
|
Events.track('new user', {username: user.username, email: user.profile.email});
|
|
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
Telescope.callbacks.register("userCreated", setupUser);
|
2015-04-23 17:45:37 +09:00
|
|
|
|
|
2015-05-06 12:33:48 +09:00
|
|
|
|
|
2015-04-23 17:45:37 +09:00
|
|
|
|
/**
|
|
|
|
|
* Check if the user has completed their profile with an email and username.
|
|
|
|
|
* @param {Object} user
|
|
|
|
|
*/
|
|
|
|
|
function hasCompletedProfile (user) {
|
|
|
|
|
return !!Users.getEmail(user) && !!Users.getUserName(user);
|
|
|
|
|
}
|
2015-05-06 12:28:00 +09:00
|
|
|
|
Telescope.callbacks.register("profileCompletedChecks", hasCompletedProfile);
|