本文整理匯總了TypeScript中meteor/meteor.Meteor.users.remove方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Meteor.users.remove方法的具體用法?TypeScript Meteor.users.remove怎麽用?TypeScript Meteor.users.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類meteor/meteor.Meteor.users
的用法示例。
在下文中一共展示了Meteor.users.remove方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addTestUser
function addTestUser(username:string, email:string, role:string) {
let existsUser:any = Accounts.findUserByEmail(email) ? true : false;
if (existsUser) {
Meteor.users.remove({_id: existsUser._id});
}
const password = "1234";
log.info("Created Username:" + username + ", email: " + email +", password:" + password + ", role:" + role );
var user = Accounts.createUser({username: username, email: email, password: password});
Roles.addUsersToRoles(user, [role]);
}
示例2: extend
Accounts.onCreateUser((options, user) => {
let currentService, loginEmail;
user.profile = extend({}, user.profile, options.profile);
if (user.services) {
currentService = first(keys(user.services));
loginEmail = user.services[currentService].email;
}
const originalUser = Meteor.users.findOne({'verified_emails': loginEmail});
if (!originalUser) {
return user;
}
// remove old account
try {
Meteor.users.remove(originalUser._id);
} catch (e) {
throw new Meteor.Error(500, e.toString());
}
// add the services to the new account
for (let service of REGISTERED_SERVICES) {
if (originalUser.services[service]) {
user.services[service] = originalUser.services[service];
}
}
// update posts
Posts.update({ author: originalUser._id }, { $set: { author: user._id }}, { multi: true });
user.profile = extend({}, originalUser.profile, user.profile, options.profile);
return user;
});
示例3: if
Accounts.onCreateUser((options, user) => {
// Grab the default profile object if it exists.
const profile = (options.profile !== undefined) ? options.profile : user.profile;
let service;
let address;
if (user.services) {
for (const serviceName in user.services) {
if (Object.hasOwnProperty.call(user.services, serviceName)) {
service = user.services[serviceName];
address = (service.email) ? service.email : false;
if (!address) {
const emails = (serviceName === 'password') ? user.emails : service.emails;
for (let i = 0; i < emails.length; i++) {
const email = emails[i];
if (email.primary) {
address = email.address;
}
}
}
if (service.username && !profile.name) {
profile.name = service.username;
}
// Create or merge the profiles if needed.
if (!user.profile && profile) {
user.profile = profile;
} else if (profile) {
user.profile = Object.assign(profile, user.profile);
}
if (address) {
const _emails = user.emails || [];
_emails.push({ address });
user.emails = _emails;
} else {
return user;
}
}
}
// BEWARE!!! Hackery below
// See if any existing user has this email address, otherwise create new
// From http://meteorpedia.com/read/Merging_OAuth_accounts
const existingUser = Meteor.users.findOne({ 'emails.address': address });
if (!existingUser) {
return user;
}
// Precaution: these will exist from accounts-password if used
if (!existingUser.services) {
existingUser.services = {
resume: {
loginTokens: [],
},
};
}
if (!existingUser.services.resume) {
existingUser.services.resume = {
loginTokens: [],
};
}
// Copy accross new service info
existingUser.services[service] = user.services[service];
if (user.services.resume) {
if (user.services.resume.loginTokens) {
existingUser.services.resume.loginTokens.push(
user.services.resume.loginTokens[0]
);
}
}
// Create emails if needed.
if (!existingUser.emails && user.emails) {
existingUser.emails = user.emails;
}
// Create or merge the profiles if needed.
if (!existingUser.profile && user.profile) {
existingUser.profile = user.profile;
} else if (user.profile) {
existingUser.profile = Object.assign(user.profile, existingUser.profile);
}
// Even worse hackery
Meteor.users.remove({ _id: existingUser._id }); // Remove the existing record
return existingUser; // Record is re-inserted
}
return user;
});
示例4: function
// console.log("selector" + selector)
// console.dir(selector)
// console.dir(options)
// console.log("searchString" + searchString)
// return Meteor.users.find(selector , options);
// });
Meteor.methods({
'users.insert'(user) {
Meteor.users.insert(user);
},
'users.remove'(userId) {
Meteor.users.remove(userId);
},
'users.update'(userId, action) {
Meteor.users.update(userId, action);
},
'users.getUsers'() {
console.log('on server, Meteor.users.find({}) called');
return Meteor.users.find({}).fetch();
},
});
Meteor.users.allow({
insert: function () {
return true;
},
示例5:
options.users.forEach((user:any)=>{
let r = Meteor.users.remove({_id: user});
console.log(r);
});
示例6:
Meteor.startup(() => {
Posts.remove({});
TimeLines.remove({});
Meteor.users.remove({});
});