• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript cafy.str类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: function

export default async function(screenName: string, password: string, config: IWebAppConfig): Promise<IValidResult | IInvalidResult> {
	if ($.str.nok(screenName) || $.str.nok(password)) {
		throw new HttpError(400, { error: { reason: 'invalid_param' } });
	}
	// * validate credential
	const validation = await axios.post(`${config.apiBaseUrl}/auth/credential/validate`, {
		screenName: screenName,
		password: password
	}, { headers: { authorization: `bearer ${config.hostToken.accessToken}` }, validateStatus: () => true });
	// expect: status 200 or error invalid_param_format
	if (validation.status != 200 && (validation.status != 400 || validation.data.error.reason != 'invalid_param_format')) {
		log('failed to request /auth/credential/validate');
		log('statusCode:', validation.status);
		log('data:', validation.data);
		throw new HttpError(500, { error: { reason: 'server_error' } });
	}
	if (validation.status == 400) {
		return {
			isValid: false
		};
	}
	return {
		isValid: validation.data.result.isValid,
		userId: validation.data.result.userId
	};
}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:26,代码来源:validateCredential.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: 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


示例4: 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


示例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 '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


示例7: 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


示例8: 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


示例9: 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


示例10: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript camelot-unchained.RUNTIME_ASSERT函数代码示例发布时间:2022-05-25
下一篇:
TypeScript cafy.type函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap