当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Random.id方法代码示例

本文整理汇总了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());
   }
 }
开发者ID:Apetrich,项目名称:square-meter,代码行数:6,代码来源:cart.ts

示例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 };
	},
开发者ID:djulls07,项目名称:projects-manager,代码行数:62,代码来源:projects.ts


注:本文中的meteor/random.Random.id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。