Permalink
Browse files

Step 15.8: Re-add fake users and whitelist them in the publication

  • Loading branch information...
darkbasic committed Oct 12, 2017
1 parent 794c94c commit c2dceafed874692b8a46f0bed4446d17e2106466
Showing with 87 additions and 2 deletions.
  1. +77 −0 api/server/main.ts
  2. +10 −2 api/server/publications.ts
View
@@ -1,9 +1,86 @@
import { Meteor } from 'meteor/meteor';
import { Picture } from './models';
import { Accounts } from 'meteor/accounts-base';
import { Users } from './collections/users';
Meteor.startup(() => {
if (Meteor.settings) {
Object.assign(Accounts._options, Meteor.settings['accounts-phone']);
SMS.twilio = Meteor.settings['twilio'];
}
if (Users.collection.find().count() > 0) {
return;
}
let picture = importPictureFromUrl({
name: 'man1.jpg',
url: 'https://randomuser.me/api/portraits/men/1.jpg'
});
Accounts.createUserWithPhone({
phone: '+972540000001',
profile: {
name: 'Ethan Gonzalez',
pictureId: picture._id
}
});
picture = importPictureFromUrl({
name: 'lego1.jpg',
url: 'https://randomuser.me/api/portraits/lego/1.jpg'
});
Accounts.createUserWithPhone({
phone: '+972540000002',
profile: {
name: 'Bryan Wallace',
pictureId: picture._id
}
});
picture = importPictureFromUrl({
name: 'woman1.jpg',
url: 'https://randomuser.me/api/portraits/women/1.jpg'
});
Accounts.createUserWithPhone({
phone: '+972540000003',
profile: {
name: 'Avery Stewart',
pictureId: picture._id
}
});
picture = importPictureFromUrl({
name: 'woman2.jpg',
url: 'https://randomuser.me/api/portraits/women/2.jpg'
});
Accounts.createUserWithPhone({
phone: '+972540000004',
profile: {
name: 'Katie Peterson',
pictureId: picture._id
}
});
picture = importPictureFromUrl({
name: 'man2.jpg',
url: 'https://randomuser.me/api/portraits/men/2.jpg'
});
Accounts.createUserWithPhone({
phone: '+972540000005',
profile: {
name: 'Ray Edwards',
pictureId: picture._id
}
});
});
function importPictureFromUrl(options: { name: string, url: string }): Picture {
const description = { name: options.name };
return Meteor.call('ufsImportURL', options.url, description, 'pictures');
}
View
@@ -17,10 +17,18 @@ Meteor.publishComposite('users', function(
if (pattern) {
selector = {
'profile.name': { $regex: pattern, $options: 'i' },
'phone.number': {$in: contacts}
$or: [
{'phone.number': {$in: contacts}},
{'profile.name': {$in: ['Ethan Gonzalez', 'Bryan Wallace', 'Avery Stewart', 'Katie Peterson', 'Ray Edwards']}}
]
};
} else {
selector = {'phone.number': {$in: contacts}}
selector = {
$or: [
{'phone.number': {$in: contacts}},
{'profile.name': {$in: ['Ethan Gonzalez', 'Bryan Wallace', 'Avery Stewart', 'Katie Peterson', 'Ray Edwards']}}
]
}
}
return {

0 comments on commit c2dceaf

Please sign in to comment.