mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 18:11:40 -05:00
cleaning up user helpers
This commit is contained in:
parent
2e168dbfec
commit
2bb4913fb2
5 changed files with 79 additions and 51 deletions
|
@ -80,7 +80,7 @@ Template.comment_item.helpers({
|
||||||
return Meteor.users.findOne(this.userId);
|
return Meteor.users.findOne(this.userId);
|
||||||
},
|
},
|
||||||
authorName: function(){
|
authorName: function(){
|
||||||
return Users.getAuthorName(this);
|
return Users.getDisplayName(this);
|
||||||
},
|
},
|
||||||
showChildComments: function(){
|
showChildComments: function(){
|
||||||
// TODO: fix this
|
// TODO: fix this
|
||||||
|
|
|
@ -26,6 +26,7 @@ Package.onUse(function (api) {
|
||||||
'tap:i18n@1.4.1',
|
'tap:i18n@1.4.1',
|
||||||
'fourseven:scss@2.1.1',
|
'fourseven:scss@2.1.1',
|
||||||
'iron:router@1.0.5',
|
'iron:router@1.0.5',
|
||||||
|
'dburles:collection-helpers@1.0.3',
|
||||||
// 'meteorhacks:flow-router@1.5.0',
|
// 'meteorhacks:flow-router@1.5.0',
|
||||||
// 'meteorhacks:flow-layout@1.1.1',
|
// 'meteorhacks:flow-layout@1.1.1',
|
||||||
'matb33:collection-hooks@0.7.11',
|
'matb33:collection-hooks@0.7.11',
|
||||||
|
|
|
@ -32,7 +32,7 @@ buildCampaign = function (postsArray) {
|
||||||
|
|
||||||
// the naked post object as stored in the database is missing a few properties, so let's add them
|
// the naked post object as stored in the database is missing a few properties, so let's add them
|
||||||
var properties = _.extend(post, {
|
var properties = _.extend(post, {
|
||||||
authorName: Users.getAuthorName(post),
|
authorName: Users.getDisplayName(post),
|
||||||
postLink: Posts.getLink(post),
|
postLink: Posts.getLink(post),
|
||||||
profileUrl: Users.getProfileUrl(postUser),
|
profileUrl: Users.getProfileUrl(postUser),
|
||||||
postPageLink: Posts.getPageUrl(post),
|
postPageLink: Posts.getPageUrl(post),
|
||||||
|
|
|
@ -9,12 +9,6 @@ Template.postContent.helpers({
|
||||||
var time = this.status === Posts.config.STATUS_APPROVED ? this.postedAt : this.createdAt;
|
var time = this.status === Posts.config.STATUS_APPROVED ? this.postedAt : this.createdAt;
|
||||||
return moment(time).format("MMMM Do, h:mm:ss a");
|
return moment(time).format("MMMM Do, h:mm:ss a");
|
||||||
},
|
},
|
||||||
userAvatar: function(){
|
|
||||||
// THIS FUNCTION IS DEPRECATED -- package bengott:avatar is used instead.
|
|
||||||
var author = Meteor.users.findOne(this.userId, {reactive: false});
|
|
||||||
if(!!author)
|
|
||||||
return Users.getAvatarUrl(author); // ALSO DEPRECATED
|
|
||||||
},
|
|
||||||
inactiveClass: function(){
|
inactiveClass: function(){
|
||||||
return (Users.is.admin(Meteor.user()) && this.inactive) ? i18n.t('inactive') : "";
|
return (Users.is.admin(Meteor.user()) && this.inactive) ? i18n.t('inactive') : "";
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
///////////////////
|
////////////////////
|
||||||
// Users Helpers //
|
// User Getters //
|
||||||
///////////////////
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Users.updateAdmin = function (userId, admin) {
|
|
||||||
this.update(userId, {$set: {isAdmin: admin}});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Users.adminUsers = function () {
|
|
||||||
return this.find({isAdmin : true}).fetch();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's username (unique, no special characters or spaces)
|
||||||
|
* @param {Object} user
|
||||||
|
*/
|
||||||
Users.getUserName = function (user) {
|
Users.getUserName = function (user) {
|
||||||
try{
|
try{
|
||||||
if (user.username)
|
if (user.username)
|
||||||
|
@ -25,32 +18,44 @@ Users.getUserName = function (user) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Users.helpers({getUserName: function () {return Users.getUserName(this);}});
|
||||||
|
Users.getUserNameById = function (userId) {return Users.getUserName(Meteor.users.findOne(userId))};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's display name (not unique, can take special characters and spaces)
|
||||||
|
* @param {Object} user
|
||||||
|
*/
|
||||||
Users.getDisplayName = function (user) {
|
Users.getDisplayName = function (user) {
|
||||||
return (user.telescope && user.telescope.displayName) ? user.telescope.displayName : Users.getUserName(user);
|
if (typeof user === "undefined") {
|
||||||
};
|
return "";
|
||||||
|
} else {
|
||||||
Users.getDisplayNameById = function (userId) {
|
return (user.telescope && user.telescope.displayName) ? user.telescope.displayName : Users.getUserName(user);
|
||||||
return this.getDisplayName(Meteor.users.findOne(userId));
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Users.getAuthorName = function(item) {
|
|
||||||
var user = Meteor.users.findOne(item.userId);
|
|
||||||
return typeof user === 'undefined' ? '' : Users.getDisplayName(user);
|
|
||||||
};
|
};
|
||||||
|
Users.helpers({getDisplayName: function () {return Users.getDisplayName(this);}});
|
||||||
|
Users.getDisplayNameById = function (userId) {return Users.getDisplayName(Meteor.users.findOne(userId));};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's profile URL
|
||||||
|
* @param {Object} user
|
||||||
|
*/
|
||||||
Users.getProfileUrl = function (user) {
|
Users.getProfileUrl = function (user) {
|
||||||
return this.getProfileUrlBySlugOrId(user.telescope.slug);
|
return this.getProfileUrlBySlugOrId(user.telescope.slug);
|
||||||
};
|
};
|
||||||
|
Users.helpers({getProfileUrl: function () {return Users.getProfileUrl(this);}});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's profile URL by slug or Id
|
||||||
|
* @param {String} slugOrId
|
||||||
|
*/
|
||||||
Users.getProfileUrlBySlugOrId = function (slugOrId) {
|
Users.getProfileUrlBySlugOrId = function (slugOrId) {
|
||||||
return Telescope.utils.getRouteUrl('user_profile', {_idOrSlug: slugOrId});
|
return Telescope.utils.getRouteUrl('user_profile', {_idOrSlug: slugOrId});
|
||||||
};
|
};
|
||||||
|
|
||||||
Users.hasPassword = function (user) {
|
/**
|
||||||
return !!user.services.password;
|
* Get a user's Twitter name
|
||||||
};
|
* @param {Object} user
|
||||||
|
*/
|
||||||
Users.getTwitterName = function (user) {
|
Users.getTwitterName = function (user) {
|
||||||
// return twitter name provided by user, or else the one used for twitter login
|
// return twitter name provided by user, or else the one used for twitter login
|
||||||
if(Telescope.utils.checkNested(user, 'profile', 'twitter')){
|
if(Telescope.utils.checkNested(user, 'profile', 'twitter')){
|
||||||
|
@ -60,7 +65,13 @@ Users.getTwitterName = function (user) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
Users.helpers({getTwitterName: function () {return Users.getTwitterName(this);}});
|
||||||
|
Users.getTwitterNameById = function (userId) {return Users.getTwitterName(Meteor.users.findOne(userId));};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's GitHub name
|
||||||
|
* @param {Object} user
|
||||||
|
*/
|
||||||
Users.getGitHubName = function (user) {
|
Users.getGitHubName = function (user) {
|
||||||
// return twitter name provided by user, or else the one used for twitter login
|
// return twitter name provided by user, or else the one used for twitter login
|
||||||
if(Telescope.utils.checkNested(user, 'profile', 'github')){
|
if(Telescope.utils.checkNested(user, 'profile', 'github')){
|
||||||
|
@ -70,13 +81,13 @@ Users.getGitHubName = function (user) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
Users.helpers({getGitHubName: function () {return Users.getGitHubName(this);}});
|
||||||
|
Users.getGitHubNameById = function (userId) {return Users.getGitHubName(Meteor.users.findOne(userId));};
|
||||||
|
|
||||||
Users.getTwitterNameById = function (userId) {
|
/**
|
||||||
var user = Meteor.users.findOne(userId);
|
* Get a user's email
|
||||||
if (user)
|
* @param {Object} user
|
||||||
return Users.getTwitterName(user);
|
*/
|
||||||
};
|
|
||||||
|
|
||||||
Users.getEmail = function (user) {
|
Users.getEmail = function (user) {
|
||||||
if(user.telescope && user.telescope.email){
|
if(user.telescope && user.telescope.email){
|
||||||
return user.telescope.email;
|
return user.telescope.email;
|
||||||
|
@ -84,21 +95,24 @@ Users.getEmail = function (user) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Users.helpers({getEmail: function () {return Users.getEmail(this);}});
|
||||||
|
Users.getEmailById = function (userId) {return Users.getEmail(Meteor.users.findOne(userId));};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's email hash
|
||||||
|
* @param {Object} user
|
||||||
|
*/
|
||||||
Users.getEmailHash = function (user) {
|
Users.getEmailHash = function (user) {
|
||||||
// has to be this way to work with Gravatar
|
// has to be this way to work with Gravatar
|
||||||
return Gravatar.hash(Users.getEmail(user));
|
return Gravatar.hash(Users.getEmail(user));
|
||||||
};
|
};
|
||||||
|
Users.helpers({getEmailHash: function () {return Users.getEmailHash(this);}});
|
||||||
|
Users.getEmailHashById = function (userId) {return Users.getEmailHash(Meteor.users.findOne(userId));};
|
||||||
|
|
||||||
Users.getAvatarUrl = function (user) {
|
/**
|
||||||
console.warn('FUNCTION getAvatarUrl() IS DEPRECATED -- package bengott:avatar is used instead.');
|
* Check if a user's profile is complete
|
||||||
return Avatar.getUrl(user);
|
* @param {Object} user
|
||||||
};
|
*/
|
||||||
|
|
||||||
Users.getCurrentUserEmail = function () {
|
|
||||||
return Meteor.user() ? Users.getEmail(Meteor.user()) : '';
|
|
||||||
};
|
|
||||||
|
|
||||||
Users.userProfileComplete = function (user) {
|
Users.userProfileComplete = function (user) {
|
||||||
for (var i = 0; i < Telescope.callbacks.profileCompletedChecks.length; i++) {
|
for (var i = 0; i < Telescope.callbacks.profileCompletedChecks.length; i++) {
|
||||||
if (!Telescope.callbacks.profileCompletedChecks[i](user)) {
|
if (!Telescope.callbacks.profileCompletedChecks[i](user)) {
|
||||||
|
@ -107,6 +121,12 @@ Users.userProfileComplete = function (user) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
Users.helpers({userProfileComplete: function () {return Users.userProfileComplete(this);}});
|
||||||
|
Users.userProfileCompleteById = function (userId) {return Users.userProfileComplete(Meteor.users.findOne(userId));};
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
// Other Helpers //
|
||||||
|
///////////////////
|
||||||
|
|
||||||
Users.findLast = function (user, collection) {
|
Users.findLast = function (user, collection) {
|
||||||
return collection.findOne({userId: user._id}, {sort: {createdAt: -1}});
|
return collection.findOne({userId: user._id}, {sort: {createdAt: -1}});
|
||||||
|
@ -225,3 +245,16 @@ Users.getSubParams = function(filterBy, sortBy, limit) {
|
||||||
options: { sort: sort, limit: limit }
|
options: { sort: sort, limit: limit }
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Users.updateAdmin = function (userId, admin) {
|
||||||
|
this.update(userId, {$set: {isAdmin: admin}});
|
||||||
|
};
|
||||||
|
|
||||||
|
Users.adminUsers = function () {
|
||||||
|
return this.find({isAdmin : true}).fetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
Users.getCurrentUserEmail = function () {
|
||||||
|
return Meteor.user() ? Users.getEmail(Meteor.user()) : '';
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue