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


TypeScript r.text函数代码示例

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


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

示例1: accountName

export function accountName(aAccountName : string, locale : string) : ValidationResult
{
    let status = Response.Status.FAILED;
    let message : string;
    const _accountName = aAccountName || '';

    do
    {
        const min = 1;
        const max = 20;

        if (_accountName !== _accountName.trim())
        {
            message = R.text(R.CANNOT_ENTER_ACCOUNT_NAME_BEFORE_AFTER_SPACE, locale);
            break;
        }

        const len = _accountName.length;
        if (len < min || max < len)
        {
            message = R.text(R.ACCOUNT_NAME_TOO_SHORT_OR_TOO_LONG, locale, {min, max});
            break;
        }

        status = Response.Status.OK;
    }
    while (false);
    return ({status, message});
}
开发者ID:nandai,项目名称:web-service-template,代码行数:29,代码来源:accountName.ts

示例2: email

export async function email(aEmail : string, accountId : number, alreadyExistsAccount : Account, locale : string) : Promise<ValidationResult>
{
    const log = slog.stepIn('Validator', 'email');
    let status = Response.Status.FAILED;
    let message : string;

    do
    {
        if (! aEmail || nodeValidator.isEmail(aEmail) === false)
        {
            message = R.text(R.INVALID_EMAIL, locale);
            break;
        }

        if (alreadyExistsAccount && alreadyExistsAccount.id !== accountId)
        {
            message = R.text(R.ALREADY_EXISTS_EMAIL, locale);
            break;
        }

        const hostname = aEmail.split('@')[1];
        if (await Utils.existsHost(hostname) === false)
        {
            message = R.text(R.INVALID_EMAIL, locale);
            break;
        }

        status = Response.Status.OK;
    }
    while (false);

    log.stepOut();
    return {status, message};
}
开发者ID:nandai,项目名称:web-service-template,代码行数:34,代码来源:email.ts

示例3: execInvite

/**
 * 実行
 */
async function execInvite(param : Request.Invite, locale : string) : Promise<Response.Invite>
{
    const log = slog.stepIn('SettingsApi', 'execInvite');
    const response : Response.Invite = {status:Response.Status.FAILED, message:{}};
    const {email} = param;

    const invite_id = Utils.createRandomText(32);
    const url = Utils.generateUrl('join', invite_id);
    const template = R.mail(R.NOTICE_INVITE, locale);
    const contents = CommonUtils.formatString(template.contents, {url});
    const result = await Utils.sendMail(template.subject, email, contents);

    if (result)
    {
        response.status = Response.Status.OK;
        response.message.general = R.text(R.INVITE_MAIL_SENDED, locale);

        const name = email.substr(0, email.indexOf('@'));
        const account : Account = {name, email, invite_id};
        await AccountAgent.add(account);
    }
    else
    {
        response.message.email = R.text(R.COULD_NOT_SEND_INVITE_MAIL, locale);
    }

    log.stepOut();
    return response;
}
开发者ID:nandai,项目名称:web-service-template,代码行数:32,代码来源:onInvite.ts

示例4: isConfirmSignupEmailValid

export function isConfirmSignupEmailValid(param : Request.ConfirmSignupEmail, account : Account, locale : string) : ValidationResult
{
    const log = slog.stepIn('SignupApi', 'isConfirmSignupEmailValid');
    const response : Response.ConfirmSignupEmail = {status:Response.Status.OK, message:{}};

    do
    {
        if (account === null)
        {
            // サインアップの確認画面でサインアップを完了させた後、再度サインアップを完了させようとした場合にここに到達する想定。
            // サインアップIDで該当するアカウントがないということが必ずしもサインアップ済みを意味するわけではないが、
            // 第三者が直接このAPIをコールするなど、想定以外のケースでなければありえないので、登録済みというメッセージでOK。
            response.status = Response.Status.FAILED;
            response.message.general = R.text(R.ALREADY_SIGNUP, locale);
            break;
        }

        const hashPassword = Utils.getHashPassword(account.email, param.password, Config.PASSWORD_SALT);

        if (account.password !== hashPassword)
        {
            response.status = Response.Status.FAILED;
            response.message.password = R.text(R.INVALID_PASSWORD, 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,代码行数:34,代码来源:onConfirmSignupEmail.ts

示例5: onRequestResetPassword

export async function onRequestResetPassword(req : express.Request, res : express.Response)
{
    const log = slog.stepIn('ResetApi', 'onRequestResetPassword');
    try
    {
        do
        {
            const locale = req.ext.locale;
            const param     : Request.RequestResetPassword = req.body;
            const condition : Request.RequestResetPassword =
            {
                email: ['string', null, true] as any
            };

            if (Utils.existsParameters(param, condition) === false)
            {
                res.ext.badRequest(locale);
                break;
            }

            const response : Response.RequestResetPassword = {status:Response.Status.FAILED, message:{}};
            const account = await AccountAgent.findByProviderId('email', param.email);
            if (account === null || account.signup_id)
            {
                response.message.email = R.text(R.INVALID_EMAIL, locale);
                res.json(response);
                break;
            }

            account.reset_id = Utils.createRandomText(32);
            await AccountAgent.update(account);

            const url = Utils.generateUrl('reset', account.reset_id);
            const template = R.mail(R.NOTICE_RESET_PASSWORD, locale);
            const contents = CommonUtils.formatString(template.contents, {url});
            const result = await Utils.sendMail(template.subject, account.email, contents);

            if (result)
            {
                response.status = Response.Status.OK;
                response.message.general = R.text(R.RESET_MAIL_SENDED, locale);
            }
            else
            {
                response.message.email = R.text(R.COULD_NOT_SEND_RESET_MAIL, locale);
            }

            res.json(response);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:54,代码来源:onRequestResetPassword.ts

示例6: userName

export function userName(aUserName : string, accountId : number, alreadyExistsAccount : Account, locale : string) : ValidationResult
{
    let status = Response.Status.FAILED;
    let message : string;

    do
    {
        const min = 0;
        const max = 20;

        if (! aUserName)
        {
            status = Response.Status.OK;
            break;
        }

        if (aUserName !== aUserName.trim())
        {
            message = R.text(R.CANNOT_ENTER_USER_NAME_BEFORE_AFTER_SPACE, locale);
            break;
        }

        const len = aUserName.length;
        if (len < min || max < len)
        {
            message = R.text(R.USER_NAME_TOO_LONG, locale, {min, max});
            break;
        }

        if (aUserName && isNaN(Number(aUserName)) === false)
        {
            message = R.text(R.CANNOT_ENTER_USER_NAME_ONLY_NUMBERS, locale);
            break;
        }

        if (aUserName.match(/^[0-9a-zA-Z-_]+$/) === null)
        {
            message = R.text(R.ENTER_ALPHABETICAL_NUMBER_BAR, locale);
            break;
        }

        if (alreadyExistsAccount && alreadyExistsAccount.id !== accountId)
        {
            message = R.text(R.ALREADY_USE_USER_NAME, locale);
            break;
        }

        status = Response.Status.OK;
    }
    while (false);
    return ({status, message});
}
开发者ID:nandai,项目名称:web-service-template,代码行数:52,代码来源:userName.ts

示例7: password

export function password(args : {password : string, confirm? : string, canNull? : boolean}, locale : string)
{
    const {confirm, canNull} = args;
    const _password = args.password;
    const result =
    {
        status:   Response.Status.OK,
        password: null as string,
        confirm:  null as string
    };

    do
    {
        const min = 8;
        const max = 16;

        if (_password === null)
        {
            if (confirm === undefined || canNull !== true)
            {
                result.status = Response.Status.FAILED;
                result.password = R.text(R.PASSWORD_TOO_SHORT_OR_TOO_LONG, locale, {min, max});
            }
        }
        else
        {
            const len = _password.length;
            if (len < min || max < len)
            {
                result.status = Response.Status.FAILED;
                result.password = R.text(R.PASSWORD_TOO_SHORT_OR_TOO_LONG, locale, {min, max});
            }
            else if (_password.match(/^[0-9a-zA-Z@]+$/) === null)
            {
                result.status = Response.Status.FAILED;
                result.password = R.text(R.ENTER_ALPHABETICAL_NUMBER, locale);
            }
        }

        // 確認用パスワードが一致するか
        if (confirm !== undefined && _password !== confirm)
        {
            result.status = Response.Status.FAILED;
            result.confirm = R.text(R.MISMATCH_PASSWORD, locale);
        }
    }
    while (false);
    return (result);
}
开发者ID:nandai,项目名称:web-service-template,代码行数:49,代码来源:password.ts

示例8: isChangeEmailValid

export async function isChangeEmailValid(param : Request.ChangeEmail, account : Account, locale : string) : Promise<ValidationResult>
{
        const log = slog.stepIn('SettingsApi', 'isChangeEmailValid');
        const response : Response.ChangeEmail = {status:Response.Status.OK, message:{}};
        const {password} = param;

        do
        {
            if (account === null)
            {
                // メールアドレス設定の確認画面でメールアドレスの設定を完了させた後、再度メールアドレスの設定を完了させようとした場合にここに到達する想定。
                // 変更IDで該当するアカウントがないということが必ずしもメールアドレスの設定済みを意味するわけではないが、
                // 第三者が直接このAPIをコールするなど、想定以外のケースでなければありえないので変更済みというメッセージでOK。
                response.status = Response.Status.FAILED;
                response.message.general = R.text(R.ALREADY_EMAIL_CHANGED, locale);
                break;
            }

            // メールアドレス変更メールを送信してから確認までの間に同じメールアドレスが本登録される可能性があるため、
            // メールアドレスの重複チェックを行う
            const changeEmail = account.change_email;
            const alreadyExistsAccount = await AccountAgent.findByProviderId('email', changeEmail);

            if (alreadyExistsAccount !== null && alreadyExistsAccount.signup_id === null)
            {
                response.status = Response.Status.FAILED;
                response.message.general = R.text(R.ALREADY_EXISTS_EMAIL, locale);
                break;
            }

            // パスワードチェック
            const hashPassword = Utils.getHashPassword(account.email, password, Config.PASSWORD_SALT);

            if (hashPassword !== account.password)
            {
                response.status = Response.Status.FAILED;
                response.message.password = R.text(R.INVALID_PASSWORD, 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,代码行数:48,代码来源:onChangeEmail.ts

示例9: onUnlinkProvider

export async function onUnlinkProvider(req : express.Request, res : express.Response)
{
    const log = slog.stepIn('SettingsApi', 'onUnlinkProvider');
    try
    {
        do
        {
            const locale = req.ext.locale;
            const param     : Request.UnlinkProvider = req.body;
            const condition : Request.UnlinkProvider =
            {
                provider: ['string', null, true] as any
            };

            if (Utils.existsParameters(param, condition) === false)
            {
                res.ext.badRequest(locale);
                break;
            }

            // プロバイダ名チェック
            const {provider} = param;
            log.d(`${provider}`);

            if (provider !== 'twitter'
            &&  provider !== 'facebook'
            &&  provider !== 'google'
            &&  provider !== 'github')
            {
                res.ext.badRequest(locale);
                break;
            }

            // アカウント更新
            const session : Session = req.ext.session;
            const account = await AccountAgent.find(session.account_id);

            if (AccountAgent.canUnlink(account, provider))
            {
                account[provider] = null;
                await AccountAgent.update(account);

                const response : Response.UnlinkProvider = {status:Response.Status.OK, message:{}};
                res.json(response);
            }
            else
            {
                const response : Response.UnlinkProvider =
                {
                    status: Response.Status.FAILED,
                    message: {general:R.text(R.CANNOT_UNLINK, locale)}
                };
                res.json(response);
            }
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:60,代码来源:onUnlinkProvider.ts

示例10: onLoginEmail

export async function onLoginEmail(req : express.Request, res : express.Response)
{
    const log = slog.stepIn('LoginApi', 'onLoginEmail');
    try
    {
        do
        {
            const locale = req.ext.locale;
            const param     : Request.LoginEmail = req.body;
            const condition : Request.LoginEmail =
            {
                email:    ['string', null, true] as any,
                password: ['string', null, true] as any
            };

            if (Utils.existsParameters(param, condition) === false)
            {
                res.ext.badRequest(locale);
                break;
            }

            const {email, password} = param;
            const account = await AccountAgent.findByProviderId('email', email);
            let hashPassword : string;

            if (account) {
                hashPassword = Utils.getHashPassword(email, password, Config.PASSWORD_SALT);
            }

            if (account === null || account.password !== hashPassword || account.signup_id)
            {
                const response : Response.LoginEmail =
                {
                    status: Response.Status.FAILED,
                    message: {general:R.text(R.INVALID_EMAIL_AUTH, locale)}
                };

                log.w(JSON.stringify(response, null, 2));
                res.json(response);
                break;
            }

            process.nextTick(() =>
            {
                Email.verify(email, hashPassword, (_err, user) =>
                {
                    req.ext.command = 'login';
                    req.user = user;
                    Email.callback(req, res);
                });
            });
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:57,代码来源:onLoginEmail.ts


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