本文整理汇总了TypeScript中server/libs/validator.userName函数的典型用法代码示例。如果您正苦于以下问题:TypeScript userName函数的具体用法?TypeScript userName怎么用?TypeScript userName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了userName函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: onCheckUserName
export async function onCheckUserName(req : express.Request, res : express.Response)
{
const log = slog.stepIn('SettingsApi', 'onCheckUserName');
try
{
do
{
const locale = req.ext.locale;
const param : Request.CheckUserName = req.query;
const condition : Request.CheckUserName =
{
userName: ['string', null, true] as any
};
if (Utils.existsParameters(param, condition) === false)
{
res.ext.badRequest(locale);
break;
}
const {userName} = param;
// 検証
const session : Session = req.ext.session;
const alreadyExistsAccount = await AccountAgent.findByUserName(userName);
const result = Validator.userName(userName, session.account_id, alreadyExistsAccount, locale);
let response : Response.CheckUserName;
if (result.status !== Response.Status.OK)
{
response =
{
status: result.status,
message: {userName:result.message}
};
res.json(response);
break;
}
const message = (userName ? R.text(R.CAN_USE_USER_NAME, locale) : '');
response =
{
status: Response.Status.OK,
message: {userName:message}
};
res.json(response);
}
while (false);
log.stepOut();
}
catch (err) {Utils.internalServerError(err, res, log);}
}
示例2:
test.serial('ユーザー名検証 - 英数の時は成功すること', (t) =>
{
const log = slog.stepIn('test', t['_test'].title);
const userName = 'ABC456789_abc4567890';
const accountId = 0;
const account = null;
const result = Validator.userName(userName, accountId, account, locale);
const {status} = result;
log.d(JSON.stringify(result, null, 2));
t.is(status, Response.Status.OK);
log.stepOut();
});
示例3: isSetAccountValid
export async function isSetAccountValid(param : Request.SetAccount, myAccountId : number, locale : string) : Promise<ValidationResult>
{
const log = slog.stepIn('SettingsApi', 'isSetAccountValid');
const response : Response.SetAccount = {status:Response.Status.OK, message:{}};
const {name, userName, countryCode, phoneNo, twoFactorAuth} = param;
do
{
// アカウント名チェック
const accountNameResult = Validator.accountName(name, locale);
if (accountNameResult.status !== Response.Status.OK)
{
response.status = accountNameResult.status;
response.message.name = accountNameResult.message;
}
// ユーザー名チェック
const alreadyExistsAccount = await AccountAgent.findByUserName(userName);
const userNameResult = Validator.userName(userName, myAccountId, alreadyExistsAccount, locale);
if (userNameResult.status !== Response.Status.OK)
{
response.status = userNameResult.status;
response.message.userName = userNameResult.message;
}
// 国コードチェック
if (countryCode)
{
const countries : any[] = lookup.countries({countryCallingCodes:countryCode});
if (countries.length === 0)
{
response.status = Response.Status.FAILED;
response.message.countryCode = R.text(R.INVALID_COUNTRY_CODE, locale);
}
}
// 二段階認証方式チェック
if (twoFactorAuth === 'SMS'
|| twoFactorAuth === 'Authy')
{
if (countryCode === null || phoneNo === null)
{
response.status = Response.Status.FAILED;
response.message.phoneNo = R.text(R.REQUIRE_COUNTRY_CODE_AND_PHONE_NO, locale);
}
}
else if (twoFactorAuth !== null)
{
response.status = Response.Status.BAD_REQUEST;
response.message.general = R.text(R.BAD_REQUEST, locale);
}
}
while (false);
if (response.status !== Response.Status.OK) {
log.w(JSON.stringify(response, null, 2));
}
log.stepOut();
return {response};
}