2012-10-18 17:20:20 +09:00
|
|
|
Accounts.onCreateUser(function(options, user){
|
2012-10-18 17:43:03 +09:00
|
|
|
user.profile = options.profile || {};
|
2013-01-19 18:24:18 +09:00
|
|
|
user.profile.karma = 0;
|
|
|
|
user.profile.notificationsFrequency = 1;
|
2012-11-26 17:11:21 +09:00
|
|
|
// users start pending and need to be invited
|
2012-10-05 13:59:40 +09:00
|
|
|
user.isInvited = false
|
2012-10-04 11:53:15 +10:00
|
|
|
|
2012-10-01 11:18:05 +10:00
|
|
|
if (options.email)
|
2012-10-01 13:08:46 +10:00
|
|
|
user.profile.email = options.email;
|
|
|
|
|
|
|
|
if (user.profile.email)
|
|
|
|
user.email_hash = CryptoJS.MD5(user.profile.email.trim().toLowerCase()).toString();
|
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
|
|
|
|
2012-10-19 12:42:28 +09:00
|
|
|
// if this is the first user ever, make them an admin
|
|
|
|
if ( !Meteor.users.find().count() )
|
|
|
|
user.isAdmin = true;
|
2012-10-18 17:43:03 +09:00
|
|
|
|
2012-11-26 17:11:21 +09:00
|
|
|
trackEvent('new user', {username: user.username, email: user.profile.email});
|
|
|
|
|
2012-10-01 11:18:05 +10:00
|
|
|
return user;
|
2012-10-01 13:08:46 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
// FIXME -- don't use this yet, until a) we are sure it's the right approach
|
|
|
|
// b) we also update their profile at the same time.
|
|
|
|
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
|
|
|
},
|
|
|
|
testEmail: function(){
|
|
|
|
console.log('////////////////email test…');
|
|
|
|
Email.send({from: 'info@sachagreif.com', to: 'sacha357@gmail.com', subject: 'mailgun test', text: 'lorem ipsum dolor'});
|
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);
|
2012-10-01 13:08:46 +10:00
|
|
|
}
|
2012-12-05 17:52:14 +11:00
|
|
|
});
|
|
|
|
|
|
|
|
// permissions for the profiler
|
|
|
|
Meteor.Profiler.allow = function(userId) {
|
|
|
|
var user = Meteor.users.findOne(userId);
|
|
|
|
return user && user.isAdmin;
|
|
|
|
};
|
|
|
|
|