Background:
- I collect information about a user’s organization during my signup process.
- I want this organization information to be inserted as a document into a collection of “organizations”.
- The schema for the organization includes the the user’s id
- I take the organization data from the forms and store it in a session variable-- this all works fine.
I’m wondering where the best place/time to insert this organization document as I need the user’s Id to have been generated? I suppose I can just use a method call but where should I call the method from?
On the server, I’m currently using accounts.OnCreateUser with if()s for registering with google or linkedin:
Accounts.onCreateUser(function(options, user) {
var attachData, email, picture, profileImageUrl,
profilePicture, url, service,
allEmails, firstEmail; profileImageUrl = undefined;
user.profile = user.profile || {};
//If the google service exists
if ((service = user.services) !== undefined ? service.google : undefined) {
user.emails = [
{
address: user.services.google.email,
verified: true
}
];
user.profile.firstName = user.services.google.given_name;
user.profile.lastName = user.services.google.family_name;
user.profile.avatar = user.services.google.picture;
}
//If the linkedin service exists
if ((service = user.services) !== undefined ? service.linkedin : undefined) {
var accessToken = user.services.linkedin.accessToken;
// http://developer.linkedin.com/documents/profile-fields
var basicProfileFields = ['first-name', 'last-name', 'maiden-name', 'formatted-name', 'phonetic-first-name',
'phonetic-last-name', 'formatted-phonetic-name', 'headline', 'location',
'industry', 'num-connections', 'num-connections-capped', 'summary',
'specialties', 'positions', 'picture-url', 'picture-urls::(original)', 'site-standard-profile-request'],
emailFields = ['email-address'],
fullProfileFields = ['last-modified-timestamp', 'proposal-comments', 'associations', 'interests', 'publications',
'patents', 'languages', 'skills', 'certifications', 'educations',
'courses', 'volunteer', 'three-current-positions', 'three-past-positions', 'num-recommenders',
'recommendations-received', 'following', 'job-bookmarks', 'suggestions', 'date-of-birth'],
contactInfoFields = ['phone-numbers', 'bound-account-types', 'im-accounts', 'main-address', 'twitter-accounts', 'primary-twitter-account'];
var requestUrl = 'https://api.linkedin.com/v1/people/~:(' + _.union(basicProfileFields, emailFields, fullProfileFields, contactInfoFields).join(',') + ')';
var response = HTTP.get(requestUrl, {
params: {
oauth2_access_token: accessToken,
format: 'json'
}
});
user.emails = [ { address: response.data.emailAddress, verified: true } ];
user.profile.firstName = response.data.firstName;
user.profile.lastName = response.data.lastName;
user.profile.avatar = response.data.pictureUrl;
user.profile.bio = response.data.summary;
}
return user;
});