Ejemplo n.º 1
0
Accounts.onCreateUser(function(options, user) {
    // Generate a user ID ourselves as we will be using it for the group member.
    user._id = Random.id();

    console.log("onCreateUser: "******"Creating a default group for user..." );
    const groupId = createUserGroup(user);
    user.groupId = groupId;
    console.log("User's default group created: " + user.groupId);

    //TODO: This is temporarily.  Eventually we will support custom profile images
    //where users can upload their own pics or we will take the pic from google/fb account
    //if user has connected their accounts.  For now, during MVP - gravatar will do.
    user.profileImage = Gravatar.imageUrl(email, {size: 50, default: 'wavatar'});

    if (options.profile) {
        user.profile = options.profile;
    }

    return user;
});
Ejemplo n.º 2
0
function getUserGravatar(currentUser, size) {
  const options = {
    secure: true,
    size: size,
    default: "identicon"
  };
  const user = currentUser || Accounts.user();
  if (!user) {
    return false;
  }
  const account = Collections.Accounts.findOne(user._id);
  // first we check picture exists. Picture has higher priority to display
  if (account && account.profile && account.profile.picture) {
    return account.profile.picture;
  }
  if (user.emails && user.emails.length === 1) {
    const email = user.emails[0].address;
    return Gravatar.imageUrl(email, options);
  }
}
Ejemplo n.º 3
0
function usersEditCheckEmail (modifier, user) {
  // if email is being modified, update user.emails too
  if (modifier.$set && modifier.$set.email) {

    const newEmail = modifier.$set.email;

    // check for existing emails and throw error if necessary
    const userWithSameEmail = Users.findByEmail(newEmail);
    if (userWithSameEmail && userWithSameEmail._id !== user._id) {
      throw new Error(Utils.encodeIntlError({id:"users.email_already_taken", value: newEmail}));
    }

    // if user.emails exists, change it too
    if (!!user.emails) {
      user.emails[0].address = newEmail;
      modifier.$set.emails = user.emails;
    }

    // update email hash
    modifier.$set.emailHash = Gravatar.hash(newEmail);

  }
  return modifier;
}
Ejemplo n.º 4
0
import { addCallback, Utils } from 'meteor/nova:lib'; // import from nova:lib because nova:core isn't loaded yet

//////////////////////////////////////////////////////
// Callbacks                                        //
//////////////////////////////////////////////////////

/**
 * @summary 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 || {},
    karma: 0,
    isInvited: false,
    postCount: 0,
    commentCount: 0,
    invitedCount: 0,
    upvotedPosts: [],
    downvotedPosts: [],
    upvotedComments: [],
    downvotedComments: []
  };
  user = _.extend(user, userProperties);

  // look in a few places for the user email
  if (options.email) {
    user.email = options.email;
  } else if (user.services['meteor-developer'] && user.services['meteor-developer'].emails) {
    user.email = _.findWhere(user.services['meteor-developer'].emails, { primary: true }).address;
  } else if (user.services.facebook && user.services.facebook.email) {
    user.email = user.services.facebook.email;
  } else if (user.services.github && user.services.github.email) {
    user.email = user.services.github.email;
  } else if (user.services.google && user.services.google.email) {
    user.email = user.services.google.email;
  } else if (user.services.linkedin && user.services.linkedin.emailAddress) {
    user.email = user.services.linkedin.emailAddress;
  }

  // generate email hash
  if (!!user.email) {
    user.emailHash = Gravatar.hash(user.email);
  }

  // look in a few places for the displayName
  if (user.profile.username) {
    user.displayName = user.profile.username;
  } else if (user.profile.name) {
    user.displayName = user.profile.name;
  } else if (user.services.linkedin && user.services.linkedin.firstName) {
    user.displayName = user.services.linkedin.firstName + " " + user.services.linkedin.lastName;
  } else {
    user.displayName = user.username;
  }

  // add Twitter username
  if (user.services && user.services.twitter && user.services.twitter.screenName) {
    user.twitterUsername = user.services.twitter.screenName;
  }

  // create a basic slug from display name and then modify it if this slugs already exists;
  const basicSlug = Utils.slugify(user.displayName);
  user.slug = Utils.getUnusedSlug(Users, basicSlug);

  // if this is not a dummy account, and is the first user ever, make them an admin
  user.isAdmin = (!user.profile.isDummy && Users.find({'profile.isDummy': {$ne: true}}).count() === 0) ? true : false;

  // Events.track('new user', {username: user.displayName, email: user.email});

  return user;
}