本文整理匯總了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};
}