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


TypeScript str.get方法代码示例

本文整理汇总了TypeScript中cafy.str.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript str.get方法的具体用法?TypeScript str.get怎么用?TypeScript str.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cafy.str的用法示例。


在下文中一共展示了str.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'currentPasword' parameter
	const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
	if (currentPasswordErr) return rej('invalid currentPasword param');

	// Get 'newPassword' parameter
	const [newPassword, newPasswordErr] = $.str.get(params.newPassword);
	if (newPasswordErr) return rej('invalid newPassword param');

	// Compare password
	const same = await bcrypt.compare(currentPassword, user.password);

	if (!same) {
		return rej('incorrect password');
	}

	// Generate hash of password
	const salt = await bcrypt.genSalt(8);
	const hash = await bcrypt.hash(newPassword, salt);

	await User.update(user._id, {
		$set: {
			'password': hash
		}
	});

	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:28,代码来源:change_password.ts

示例2: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'endpoint' parameter
	const [endpoint, endpointErr] = $.str.get(params.endpoint);
	if (endpointErr) return rej('invalid endpoint param');

	// Get 'auth' parameter
	const [auth, authErr] = $.str.get(params.auth);
	if (authErr) return rej('invalid auth param');

	// Get 'publickey' parameter
	const [publickey, publickeyErr] = $.str.get(params.publickey);
	if (publickeyErr) return rej('invalid publickey param');

	// if already subscribed
	const exist = await Subscription.findOne({
		userId: user._id,
		endpoint: endpoint,
		auth: auth,
		publickey: publickey,
		deletedAt: { $exists: false }
	});

	if (exist !== null) {
		return res();
	}

	await Subscription.insert({
		userId: user._id,
		endpoint: endpoint,
		auth: auth,
		publickey: publickey
	});

	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:35,代码来源:register.ts

示例3: default

export default (params: any) => new Promise(async (res, rej) => {
	// Get 'appSecret' parameter
	const [appSecret, appSecretErr] = $.str.get(params.appSecret);
	if (appSecretErr) return rej('invalid appSecret param');

	// Lookup app
	const app = await App.findOne({
		secret: appSecret
	});

	if (app == null) {
		return rej('app not found');
	}

	// Get 'token' parameter
	const [token, tokenErr] = $.str.get(params.token);
	if (tokenErr) return rej('invalid token param');

	// Fetch token
	const session = await AuthSess
		.findOne({
			token: token,
			appId: app._id
		});

	if (session === null) {
		return rej('session not found');
	}

	if (session.userId == null) {
		return rej('this session is not allowed yet');
	}

	// Lookup access token
	const accessToken = await AccessToken.findOne({
		appId: app._id,
		userId: session.userId
	});

	// Delete session

	/* https://github.com/Automattic/monk/issues/178
	AuthSess.deleteOne({
		_id: session._id
	});
	*/
	AuthSess.remove({
		_id: session._id
	});

	// Response
	res({
		accessToken: accessToken.token,
		user: await pack(session.userId, null, {
			detail: true
		})
	});
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:58,代码来源:userkey.ts

示例4: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'token' parameter
	const [token, tokenErr] = $.str.get(params.token);
	if (tokenErr) return rej('invalid token param');

	const _token = token.replace(/\s/g, '');

	if (user.twoFactorTempSecret == null) {
		return rej('二段階認証の設定が開始されていません');
	}

	const verified = (speakeasy as any).totp.verify({
		secret: user.twoFactorTempSecret,
		encoding: 'base32',
		token: _token
	});

	if (!verified) {
		return rej('not verified');
	}

	await User.update(user._id, {
		$set: {
			'twoFactorSecret': user.twoFactorTempSecret,
			'twoFactorEnabled': true
		}
	});

	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:30,代码来源:done.ts

示例5: default

export default (params: any) => new Promise(async (res, rej) => {
	// Get 'appSecret' parameter
	const [appSecret, appSecretErr] = $.str.get(params.appSecret);
	if (appSecretErr) return rej('invalid appSecret param');

	// Lookup app
	const app = await App.findOne({
		secret: appSecret
	});

	if (app == null) {
		return rej('app not found');
	}

	// Generate token
	const token = uuid.v4();

	// Create session token document
	const doc = await AuthSess.insert({
		createdAt: new Date(),
		appId: app._id,
		token: token
	});

	// Response
	res({
		token: doc.token,
		url: `${config.auth_url}/${doc.token}`
	});
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:30,代码来源:generate.ts

示例6: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'password' parameter
	const [password, passwordErr] = $.str.get(params.password);
	if (passwordErr) return rej('invalid password param');

	// Compare password
	const same = await bcrypt.compare(password, user.password);

	if (!same) {
		return rej('incorrect password');
	}

	// Generate secret
	const secret = generateUserToken();

	await User.update(user._id, {
		$set: {
			'token': secret
		}
	});

	res();

	// Publish event
	publishUserStream(user._id, 'my_token_regenerated');
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:26,代码来源:regenerate_token.ts

示例7: default

export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'query' parameter
	const [query, queryError] = $.str.get(params.query);
	if (queryError) return rej('invalid query param');

	// Get 'offset' parameter
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
	if (offsetErr) return rej('invalid offset param');

	// Get 'limit' parameter
	const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	if (es == null) return rej('searching not available');

	es.search({
		index: 'misskey',
		type: 'note',
		body: {
			size: limit,
			from: offset,
			query: {
				simple_query_string: {
					fields: ['text'],
					query: query,
					default_operator: 'and'
				}
			},
			sort: [
				{ _doc: 'desc' }
			]
		}
	}, async (error, response) => {
		if (error) {
			console.error(error);
			return res(500);
		}

		if (response.hits.total === 0) {
			return res([]);
		}

		const hits = response.hits.hits.map(hit => new mongo.ObjectID(hit._id));

		// Fetch found notes
		const notes = await Note.find({
			_id: {
				$in: hits
			}
		}, {
				sort: {
					_id: -1
				}
			});

		res(await Promise.all(notes.map(note => pack(note, me))));
	});
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:58,代码来源:search.ts

示例8: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'nameId' parameter
	const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
	if (nameIdErr) return rej('invalid nameId param');

	// Get 'name' parameter
	const [name, nameErr] = $.str.get(params.name);
	if (nameErr) return rej('invalid name param');

	// Get 'description' parameter
	const [description, descriptionErr] = $.str.get(params.description);
	if (descriptionErr) return rej('invalid description param');

	// Get 'permission' parameter
	const [permission, permissionErr] = $.arr($.str).unique().get(params.permission);
	if (permissionErr) return rej('invalid permission param');

	// Get 'callbackUrl' parameter
	// TODO: Check it is valid url
	const [callbackUrl = null, callbackUrlErr] = $.str.optional.nullable.get(params.callbackUrl);
	if (callbackUrlErr) return rej('invalid callbackUrl param');

	// Generate secret
	const secret = rndstr('a-zA-Z0-9', 32);

	// Create account
	const app = await App.insert({
		createdAt: new Date(),
		userId: user && user._id,
		name: name,
		nameId: nameId,
		nameIdLower: nameId.toLowerCase(),
		description: description,
		permission: permission,
		callbackUrl: callbackUrl,
		secret: secret
	});

	// Response
	res(await pack(app));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:41,代码来源:create.ts

示例9: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'token' parameter
	const [token, tokenErr] = $.str.get(params.token);
	if (tokenErr) return rej('invalid token param');

	// Fetch token
	const session = await AuthSess
		.findOne({ token: token });

	if (session === null) {
		return rej('session not found');
	}

	// Generate access token
	const accessToken = rndstr('a-zA-Z0-9', 32);

	// Fetch exist access token
	const exist = await AccessToken.findOne({
		appId: session.appId,
		userId: user._id,
	});

	if (exist === null) {
		// Lookup app
		const app = await App.findOne({
			_id: session.appId
		});

		// Generate Hash
		const sha256 = crypto.createHash('sha256');
		sha256.update(accessToken + app.secret);
		const hash = sha256.digest('hex');

		// Insert access token doc
		await AccessToken.insert({
			createdAt: new Date(),
			appId: session.appId,
			userId: user._id,
			token: accessToken,
			hash: hash
		});
	}

	// Update session
	await AuthSess.update(session._id, {
		$set: {
			userId: user._id
		}
	});

	// Response
	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:53,代码来源:accept.ts

示例10: async

/**
 * Create a file from a URL
 */
export default async (params: any, user: ILocalUser): Promise<any> => {
	// Get 'url' parameter
	// TODO: Validate this url
	const [url, urlErr] = $.str.get(params.url);
	if (urlErr) throw 'invalid url param';

	// Get 'folderId' parameter
	const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
	if (folderIdErr) throw 'invalid folderId param';

	return pack(await uploadFromUrl(url, user, folderId));
};
开发者ID:ha-dai,项目名称:Misskey,代码行数:15,代码来源:upload_from_url.ts


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