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) {
|
2015-05-08 11:45:09 +09:00
|
|
|
|
// ------------------------------ Properties ------------------------------ //
|
2015-05-06 12:28:00 +09:00
|
|
|
|
var userProperties = {
|
|
|
|
|
profile: options.profile || {},
|
|
|
|
|
telescope: {
|
|
|
|
|
karma: 0,
|
|
|
|
|
isInvited: false,
|
|
|
|
|
postCount: 0,
|
|
|
|
|
commentCount: 0,
|
|
|
|
|
invitedCount: 0,
|
|
|
|
|
upvotedPosts: [],
|
|
|
|
|
downvotedPosts: [],
|
|
|
|
|
upvotedComments: [],
|
|
|
|
|
downvotedComments: []
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
user = _.extend(user, userProperties);
|
|
|
|
|
|
2015-05-08 11:45:09 +09:00
|
|
|
|
// set email on user.telescope, and use it to generate email hash
|
2015-05-06 12:28:00 +09:00
|
|
|
|
if (options.email) {
|
|
|
|
|
user.telescope.email = options.email;
|
|
|
|
|
user.telescope.emailHash = Gravatar.hash(options.email);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-16 13:13:45 +09:00
|
|
|
|
// look in a few places for the displayName
|
|
|
|
|
if (user.profile.username) {
|
|
|
|
|
user.telescope.displayName = user.profile.username;
|
|
|
|
|
} else if (user.profile.name) {
|
|
|
|
|
user.telescope.displayName = user.profile.name;
|
|
|
|
|
} else {
|
|
|
|
|
user.telescope.displayName = user.username;
|
|
|
|
|
}
|
2015-05-06 12:28:00 +09:00
|
|
|
|
|
2015-05-19 10:26:31 +09:00
|
|
|
|
// create slug from display name
|
|
|
|
|
user.telescope.slug = Telescope.utils.slugify(user.telescope.displayName);
|
2015-05-06 12:28:00 +09:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
2015-05-17 15:38:02 +09:00
|
|
|
|
Telescope.callbacks.add("onCreateUser", 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
|
|
|
|
function hasCompletedProfile (user) {
|
2015-05-19 12:34:27 +09:00
|
|
|
|
return Users.hasCompletedProfile(user);
|
2015-04-23 17:45:37 +09:00
|
|
|
|
}
|
2015-05-17 15:38:02 +09:00
|
|
|
|
Telescope.callbacks.add("profileCompletedChecks", hasCompletedProfile);
|