daily pastebin goal
82%
SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Accounts.onCreateUser((options, user) => {
  2.   user.city = null;
  3.   user.networks = [];
  4.   user.attending = [];
  5.   if (user.profile == null) {
  6.     user.profile = {};
  7.   }
  8.   if (user.services != null) {
  9.     var service = _.keys(user.services)[0];
  10.     var email = user.services[service].email;
  11.     if (email != null) {
  12.       var oldUser = Meteor.users.findOne({
  13.         "emails.address": email
  14.       });
  15.       if (oldUser != null) {
  16.         if (oldUser.services == null) {
  17.           oldUser.services = {};
  18.         }
  19.         if (service === "google" || service === "facebook" || service === "twitter") {
  20.           oldUser.services[service] = user.services[service];
  21.           Meteor.users.remove(oldUser._id);
  22.           user = oldUser;
  23.         }
  24.       } else {
  25.         if (service === "google" || service === "facebook" || service === "twitter") {
  26.           if (user.services[service].email != null) {
  27.             user.emails = [{
  28.               address: user.services[service].email,
  29.               verified: true
  30.             }];
  31.           } else {
  32.             throw new Meteor.Error(500, service + " account has no email attached");
  33.           }
  34.           user.profile.name = user.services[service].name;
  35.         }
  36.       }
  37.     }
  38.   }
  39.   return user;
  40. });
RAW Paste Data
Top