2012-10-18 17:20:20 +09:00
|
|
|
Accounts.onCreateUser(function(options, user){
|
2013-11-14 10:49:37 +09:00
|
|
|
var userProperties = {
|
|
|
|
profile: options.profile || {},
|
|
|
|
karma: 0,
|
|
|
|
isInvited: false,
|
|
|
|
postCount: 0,
|
|
|
|
commentCount: 0,
|
2014-08-23 11:53:37 +09:00
|
|
|
invitedCount: 0,
|
|
|
|
votes: {
|
|
|
|
upvotedPosts: [],
|
|
|
|
downvotedPosts: [],
|
|
|
|
upvotedComments: [],
|
|
|
|
downvotedComments: []
|
|
|
|
}
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-11-14 10:49:37 +09:00
|
|
|
user = _.extend(user, userProperties);
|
|
|
|
|
2012-10-01 11:18:05 +10:00
|
|
|
if (options.email)
|
2012-10-01 13:08:46 +10:00
|
|
|
user.profile.email = options.email;
|
|
|
|
|
2013-11-18 11:30:58 +09:00
|
|
|
if (getEmail(user))
|
|
|
|
user.email_hash = getEmailHash(user);
|
2012-10-01 11:18:05 +10:00
|
|
|
|
2012-10-01 13:08:46 +10:00
|
|
|
if (!user.profile.name)
|
|
|
|
user.profile.name = user.username;
|
2012-10-01 11:18:05 +10:00
|
|
|
|
2013-11-18 11:30:58 +09:00
|
|
|
// set notifications default preferences
|
|
|
|
user.profile.notifications = {
|
|
|
|
users: false,
|
|
|
|
posts: false,
|
|
|
|
comments: true,
|
|
|
|
replies: true
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-11-18 11:30:58 +09:00
|
|
|
|
2013-10-24 14:24:03 +09:00
|
|
|
// create slug from username
|
|
|
|
user.slug = slugify(getUserName(user));
|
|
|
|
|
2012-10-19 12:42:28 +09:00
|
|
|
// if this is the first user ever, make them an admin
|
2014-10-03 16:21:06 -06:00
|
|
|
if (!Meteor.users.find().count() ) {
|
|
|
|
setAdmin(user, true);
|
|
|
|
} else {
|
|
|
|
setAdmin(user, false);
|
|
|
|
}
|
2012-10-18 17:43:03 +09:00
|
|
|
|
2013-10-23 19:43:42 +09:00
|
|
|
// give new users a few invites (default to 3)
|
2013-11-14 10:49:37 +09:00
|
|
|
user.inviteCount = getSetting('startInvitesCount', 3);
|
2013-10-23 19:43:42 +09:00
|
|
|
|
2012-11-26 17:11:21 +09:00
|
|
|
trackEvent('new user', {username: user.username, email: user.profile.email});
|
|
|
|
|
2013-11-14 10:04:11 +09:00
|
|
|
// if user has already filled in their email, add them to MailChimp list
|
2014-08-05 12:25:26 +09:00
|
|
|
// if(user.profile.email)
|
|
|
|
// addToMailChimpList(user, false, function(error, result){
|
|
|
|
// if(error){
|
|
|
|
// console.log(error)
|
|
|
|
// }
|
|
|
|
// });
|
2013-10-05 11:43:07 +09:00
|
|
|
|
2014-08-01 14:09:02 +02:00
|
|
|
// if the new user has been invited
|
|
|
|
// set her status accordingly and update invitation info
|
|
|
|
if(invitesEnabled() && user.profile.email){
|
|
|
|
var invite = Invites.findOne({ invitedUserEmail : user.profile.email });
|
|
|
|
if(invite){
|
|
|
|
var invitedBy = Meteor.users.findOne({ _id : invite.invitingUserId });
|
|
|
|
|
|
|
|
user = _.extend(user, {
|
|
|
|
isInvited: true,
|
|
|
|
invitedBy: invitedBy._id,
|
|
|
|
invitedByName: getDisplayName(invitedBy)
|
|
|
|
});
|
|
|
|
|
|
|
|
Invites.update(invite._id, {$set : {
|
|
|
|
accepted : true
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 11:30:58 +09:00
|
|
|
// send notifications to admins
|
2014-10-03 16:21:06 -06:00
|
|
|
var admins = adminUsers();
|
2013-11-18 11:30:58 +09:00
|
|
|
admins.forEach(function(admin){
|
|
|
|
if(getUserSetting('notifications.users', false, admin)){
|
2014-08-05 10:59:54 +09:00
|
|
|
var emailProperties = {
|
|
|
|
profileUrl: getProfileUrl(user),
|
|
|
|
username: getUserName(user)
|
2014-09-16 15:18:27 -04:00
|
|
|
};
|
2014-08-29 10:23:11 +09:00
|
|
|
var html = getEmailTemplate('emailNewUser')(emailProperties);
|
2014-08-05 10:59:54 +09:00
|
|
|
sendEmail(getEmail(admin), 'New user account: '+getUserName(user), buildEmailTemplate(html));
|
2013-11-18 11:30:58 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-01 11:18:05 +10:00
|
|
|
return user;
|
2012-10-01 13:08:46 +10:00
|
|
|
});
|
|
|
|
|
2013-11-18 11:30:58 +09:00
|
|
|
|
2012-10-01 13:08:46 +10:00
|
|
|
Meteor.methods({
|
|
|
|
changeEmail: function(newEmail) {
|
|
|
|
Meteor.users.update(Meteor.userId(), {$set: {emails: [{address: newEmail}]}});
|
2012-10-30 12:01:11 +09:00
|
|
|
},
|
|
|
|
numberOfPostsToday: function(){
|
|
|
|
console.log(numberOfItemsInPast24Hours(Meteor.user(), Posts));
|
|
|
|
},
|
|
|
|
numberOfCommentsToday: function(){
|
|
|
|
console.log(numberOfItemsInPast24Hours(Meteor.user(), Comments));
|
2012-11-21 12:30:45 +09:00
|
|
|
},
|
2012-11-26 17:11:21 +09:00
|
|
|
testBuffer: function(){
|
|
|
|
// TODO
|
2012-12-24 10:59:13 +01:00
|
|
|
},
|
|
|
|
getScoreDiff: function(id){
|
|
|
|
var object = Posts.findOne(id);
|
|
|
|
var baseScore = object.baseScore;
|
|
|
|
var ageInHours = (new Date().getTime() - object.submitted) / (60 * 60 * 1000);
|
|
|
|
var newScore = baseScore / Math.pow(ageInHours + 2, 1.3);
|
|
|
|
return Math.abs(object.score - newScore);
|
2013-01-19 22:09:47 +09:00
|
|
|
},
|
2013-11-18 11:30:58 +09:00
|
|
|
setEmailHash: function(user){
|
2014-09-12 11:54:04 +09:00
|
|
|
var hash = getEmailHash(user);
|
|
|
|
Meteor.users.update(user._id, {$set : {email_hash : hash}});
|
2012-10-01 13:08:46 +10:00
|
|
|
}
|
2014-10-03 16:21:06 -06:00
|
|
|
});
|