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


TypeScript validator.userName函数代码示例

本文整理汇总了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);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:52,代码来源:onCheckUserName.ts

示例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();
    });
开发者ID:nandai,项目名称:web-service-template,代码行数:13,代码来源:_testUserNameValid.ts

示例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};
}
开发者ID:nandai,项目名称:web-service-template,代码行数:63,代码来源:onSetAccount.ts


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