本文整理汇总了TypeScript中meteor/random.Random.id方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Random.id方法的具体用法?TypeScript Random.id怎么用?TypeScript Random.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meteor/random.Random
的用法示例。
在下文中一共展示了Random.id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor () {
this.isCartVisible = false;
if(localStorage.getItem("user_id") == null) {
localStorage.setItem("user_id", Random.id());
}
}
示例2: function
addUserProject: function(projectId: string, userEmail: string) {
let hasCreateUser = false;
if (Meteor.isServer) {
check(userEmail, String);
check(projectId, String);
let project = Projects.findOne(projectId);
let user = Meteor.user();
let pass = Random.id(8);
if (!user || !project) {
throw new Meteor.Error('403', 'not-authorized');
}
if (user._id !== project.owner) {
throw new Meteor.Error('403', 'not-authorized');
}
let userAdd = Meteor.users.findOne({ 'emails.0.address': userEmail });
if (!userAdd) {
let userId = Accounts.createUser({ email: userEmail, password: pass });
userAdd = Meteor.users.findOne(userId);
if (!userAdd) {
throw new Meteor.Error('404', 'user-not-found');
}
hasCreateUser = true;
}
let isIn = false;
project.users.forEach((userP) => {
if (userP.userId === userAdd._id) {
isIn = true;
}
});
if (!isIn) {
Projects.update(projectId, {
$push: {
users: {
email: userEmail,
userId: userAdd._id
}
}
});
}
this.unblock();
if (Meteor.isServer && hasCreateUser) {
// send email with password of account created.
// send the pass to the creator email ( not the invited user ( avoid spam ))
let to = user.emails[0].address
Email.send({
to: to,
from: process.env.MAIL_FROM,
subject: 'New user account created & invited',
text:
'You have invited a new user: "'+userEmail+'", his account has been created for you.\n'+
'Please give the your new collaborator his credentials: \n\n'+
'Login: ' + userEmail+'\n'+
'Password: ' + pass
});
}
}
return { hasCreateUser: hasCreateUser };
},