mirror of
https://github.com/vale981/Vulcan
synced 2025-03-12 05:26:38 -04:00
clean up users package files
This commit is contained in:
parent
cd1184eb43
commit
ccedc3072e
5 changed files with 72 additions and 84 deletions
|
@ -1,9 +1,55 @@
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set username on telescope
|
||||||
|
user.telescope.username = user.username;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the user has completed their profile with an email and username.
|
* Check if the user has completed their profile with an email and username.
|
||||||
* @param {Object} user
|
* @param {Object} user
|
||||||
*/
|
*/
|
||||||
function hasCompletedProfile (user) {
|
function hasCompletedProfile (user) {
|
||||||
|
return true;
|
||||||
|
//TODO
|
||||||
return !!Users.getEmail(user) && !!Users.getUserName(user);
|
return !!Users.getEmail(user) && !!Users.getUserName(user);
|
||||||
}
|
}
|
||||||
Telescope.callbacks.register("profileCompletedChecks", hasCompletedProfile);
|
Telescope.callbacks.register("profileCompletedChecks", hasCompletedProfile);
|
19
packages/telescope-users/lib/methods.js
Normal file
19
packages/telescope-users/lib/methods.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Meteor.methods({
|
||||||
|
// not used for now
|
||||||
|
changeEmail: function (userId, newEmail) {
|
||||||
|
var user = Meteor.users.findOne(userId);
|
||||||
|
if (Users.can.edit(Meteor.user(), user) !== true) {
|
||||||
|
throw new Meteor.Error("Permission denied");
|
||||||
|
}
|
||||||
|
Meteor.users.update(
|
||||||
|
userId,
|
||||||
|
{$set: {
|
||||||
|
emails: [{address: newEmail, verified: false}],
|
||||||
|
emailHash: Gravatar.hash(newEmail),
|
||||||
|
// Just in case this gets called from somewhere other than /client/views/users/user_edit.js
|
||||||
|
"profile.email": newEmail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
4
packages/telescope-users/lib/server/create_user.js
Normal file
4
packages/telescope-users/lib/server/create_user.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Accounts.onCreateUser(function(options, user){
|
||||||
|
user = Telescope.callbacks.run("userCreated", user, options);
|
||||||
|
return user;
|
||||||
|
});
|
|
@ -1,82 +0,0 @@
|
||||||
Accounts.onCreateUser(function(options, user){
|
|
||||||
|
|
||||||
// ------------------------------ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set username on telescope
|
|
||||||
user.telescope.username = user.username;
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// ------------------------------ Callbacks ------------------------------ //
|
|
||||||
|
|
||||||
// run all post submit client callbacks on properties object successively
|
|
||||||
user = Telescope.callbacks.run("userCreated", user);
|
|
||||||
|
|
||||||
// ------------------------------ Analytics ------------------------------ //
|
|
||||||
|
|
||||||
Events.track('new user', {username: user.username, email: user.profile.email});
|
|
||||||
|
|
||||||
return user;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Meteor.methods({
|
|
||||||
changeEmail: function (userId, newEmail) {
|
|
||||||
var user = Meteor.users.findOne(userId);
|
|
||||||
if (Users.can.edit(Meteor.user(), user) !== true) {
|
|
||||||
throw new Meteor.Error("Permission denied");
|
|
||||||
}
|
|
||||||
Meteor.users.update(
|
|
||||||
userId,
|
|
||||||
{$set: {
|
|
||||||
emails: [{address: newEmail, verified: false}],
|
|
||||||
emailHash: Gravatar.hash(newEmail),
|
|
||||||
// Just in case this gets called from somewhere other than /client/views/users/user_edit.js
|
|
||||||
"profile.email": newEmail
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
// numberOfPostsToday: function(){
|
|
||||||
// console.log(Users.numberOfItemsInPast24Hours(Meteor.user(), Posts));
|
|
||||||
// },
|
|
||||||
// numberOfCommentsToday: function(){
|
|
||||||
// console.log(Users.numberOfItemsInPast24Hours(Meteor.user(), Comments));
|
|
||||||
// },
|
|
||||||
testBuffer: function(){
|
|
||||||
// TODO
|
|
||||||
},
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -25,6 +25,7 @@ Package.onUse(function (api) {
|
||||||
'lib/helpers.js',
|
'lib/helpers.js',
|
||||||
'lib/menu.js',
|
'lib/menu.js',
|
||||||
'lib/pubsub.js',
|
'lib/pubsub.js',
|
||||||
|
'lib/methods.js',
|
||||||
'lib/routes.js'
|
'lib/routes.js'
|
||||||
], ['client', 'server']);
|
], ['client', 'server']);
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ Package.onUse(function (api) {
|
||||||
|
|
||||||
api.addFiles([
|
api.addFiles([
|
||||||
'lib/server/publications.js',
|
'lib/server/publications.js',
|
||||||
'lib/server/stuff.js'
|
'lib/server/create_user.js'
|
||||||
], ['server']);
|
], ['server']);
|
||||||
|
|
||||||
api.export('Users');
|
api.export('Users');
|
||||||
|
|
Loading…
Add table
Reference in a new issue