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


TypeScript account-agent.find函数代码示例

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


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

示例1: Promise

    return new Promise(async (resolve : (data : Response.GetUser) => void, reject) =>
    {
        const log = slog.stepIn('UserApi', 'getUser');
        try
        {
            const data  : Response.GetUser = {status:Response.Status.OK, user:null};
            let account : Account = null;
            const {id} = param;

            if (id)
            {
                if (isNaN(Number(id))) {
                    account = await AccountAgent.findByUserName(id as string);
                } else {
                    account = await AccountAgent.find(Number(id));
                }
            }

            if (account) {
                data.user = Converter.accountToUserResponse(account);
            }

            log.stepOut();
            resolve(data);
        }
        catch (err) {log.stepOut(); reject(err);}
    });
开发者ID:nandai,项目名称:web-service-template,代码行数:27,代码来源:getUser.ts

示例2: add

    /**
     * ログイン履歴を追加する
     *
     * @param   model   ログイン履歴
     *
     * @return  なし
     */
    static async add(model : LoginHistory, sessionId : string) : Promise<void>
    {
        const newModel = LoginHistoryAgent.toModel(model);
        delete newModel.id;
        newModel.login_at = Utils.now();

        await collection().add(newModel);

        // クライアントに通知
        const accountId = newModel.account_id;
        const account = await AccountAgent.find(accountId);

        await SocketManager.setAccountId(sessionId, accountId);
        SocketManager.notifyUpdateAccount(accountId, Converter.accountToResponse(account, newModel));
    }
开发者ID:nandai,项目名称:web-service-template,代码行数:22,代码来源:login-history-agent.ts

示例3: onDeleteAccount

export async function onDeleteAccount(req : express.Request, res : express.Response)
{
    const log = slog.stepIn('SettingsApi', 'onDeleteAccount');
    try
    {
        const session : Session = req.ext.session;
        const accountId = session.account_id;

        const account = await AccountAgent.find(accountId);
        AccountAgent.encrypt(account);

        await DeleteAccountAgent.add(account);
        await AccountAgent.remove( accountId);
        await SessionAgent.logout({accountId});

//      req.logout();

        const data : Response.DeleteAccount = {status:Response.Status.OK};
        res.json(data);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:23,代码来源:onDeleteAccount.ts

示例4: getAccount

export async function getAccount(req : express.Request) : Promise<Response.GetAccount>
{
    const log = slog.stepIn('SettingsApi', 'getAccount');
    const session    : Session = req.ext.session;
    let account      : Account =      null;
    let loginHistory : LoginHistory = null;

    if (SessionAgent.isLogin(session))
    {
        const {account_id} = session;

        account =      await AccountAgent.find(account_id);
        loginHistory = await LoginHistoryAgent.findLatest(account_id);
    }

    const data : Response.GetAccount =
    {
        status:  Response.Status.OK,
        account: Converter.accountToResponse(account, loginHistory)
    };

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

示例5: onSetAccount

export async function onSetAccount(req : express.Request, res : express.Response)
{
    const log = slog.stepIn('SettingsApi', 'onSetAccount');
    try
    {
        do
        {
            const locale = req.ext.locale;
            const param     : Request.SetAccount = req.body;
            const condition : Request.SetAccount =
            {
                name:          ['string', null, true] as any,
                userName:      ['string', null, true] as any,
                countryCode:   ['string', null, true] as any,
                phoneNo:       ['string', null, true] as any,
                twoFactorAuth: ['string', null, true] as any
            };

            log.d(JSON.stringify(param, null, 2));

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

            const {name, userName, countryCode, phoneNo} = param;
            let {twoFactorAuth} = param;

            // 検証
            const session : Session = req.ext.session;
            const result = await isSetAccountValid(param, session.account_id, locale);

            if (result.response.status !== Response.Status.OK)
            {
                res.json(result.response);
                break;
            }

            let phrase = R.SETTINGS_COMPLETED;

            // Authyからユーザーを削除する/しない
            const account = await AccountAgent.find(session.account_id);
            const newCountryCode = (countryCode && countryCode.length > 0 ? countryCode : null);
            const newPhoneNo =     (phoneNo     && phoneNo    .length > 0 ? phoneNo     : null);

            if (Config.hasAuthy())
            {
                const prevInternationalPhoneNo = AccountAgent.internationalPhoneNo(account.country_code, account.phone_no);
                const newInternationalPhoneNo =  AccountAgent.internationalPhoneNo(newCountryCode, newPhoneNo);

                if (shouldAuthyUserDelete(account, prevInternationalPhoneNo, newInternationalPhoneNo))
                {
                    const authyId = await AccountAgent.findAuthyId(prevInternationalPhoneNo, account.id);
                    if (authyId === null)
                    {
                        log.d('現在のアカウントの他には同じ電話番号がないのでAuthyからユーザーを削除します。');
                        await Authy.deleteUser(account.authy_id);
                    }
                    else
                    {
                        log.d('現在のアカウントの他に同じ電話番号があるのでAuthyからユーザー削除はしません。');
                    }
                    account.authy_id = null;
                }

                // Authyにユーザーを登録する/しない
                if (shouldAuthyUserRegister(twoFactorAuth, account, prevInternationalPhoneNo, newInternationalPhoneNo))
                {
                    if (account.email === null)
                    {
                        twoFactorAuth = account.two_factor_auth;
                        phrase = R.CANNOT_PERFORMED_WITH_AUTHY;
                    }
                    else
                    {
                        const authyId = await AccountAgent.findAuthyId(newInternationalPhoneNo);
                        if (authyId === null)
                        {
                            log.d('現在のアカウントの他に同じ電話番号がないのでAuthyにユーザーを登録します。');
                            account.authy_id = await Authy.registerUser(account.email, newCountryCode.substr(1), newPhoneNo);
                        }
                        else
                        {
                            log.d('現在のアカウントの他にも同じ電話番号があるのでAuthyにユーザー登録はしません。');
                            account.authy_id = authyId;
                        }
                    }
                }
            }

            // アカウント情報更新
            account.name =            name;
            account.user_name =       userName;
            account.country_code =    newCountryCode;
            account.phone_no =        newPhoneNo;
            account.two_factor_auth = twoFactorAuth;
            await AccountAgent.update(account);

            const data : Response.SetAccount =
//.........这里部分代码省略.........
开发者ID:nandai,项目名称:web-service-template,代码行数:101,代码来源:onSetAccount.ts

示例6: onLoginSms

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

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

            const {smsId, smsCode} = param;
            const session : Session = req.ext.session;
            let response  : Response.LoginSms;

            if (session.sms_id === smsId)
            {
                const account = await AccountAgent.find(session.account_id);
                const canTwoFactorAuth = AccountAgent.canTwoFactorAuth(account);

                if (canTwoFactorAuth === false)
                {
                    res.ext.badRequest(locale);
                    break;
                }

                let success = false;
                switch (account.two_factor_auth)
                {
                    case 'SMS':
                        success = (session.sms_code === smsCode);
                        break;

                    case 'Authy':
                        success = await Authy.verify(account.authy_id, Number(smsCode));
                        break;
                }

                if (success === false)
                {
                    response =
                    {
                        status: Response.Status.FAILED,
                        message: {smsCode:R.text(R.MISMATCH_SMS_CODE, locale)}
                    };
                    res.json(response);
                    break;
                }

                // セッション更新
                session.sms_id =     null;
                session.sms_code =   null;
                session.authy_uuid = null;
                await SessionAgent.update(session);

                // ログイン履歴作成
                const loginHistory : LoginHistory =
                {
                    account_id: account.id,
                    device:     req.headers['user-agent'] as string
                };
                await LoginHistoryAgent.add(loginHistory, session.id);
            }

            response = {status:Response.Status.OK, message:{}};
            res.json(response);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:82,代码来源:onLoginSms.ts

示例7: onRequestChangeEmail

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

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

            const changeEmail = param.email;

            // 検証
            const session : Session = req.ext.session;
            const account = await AccountAgent.find(session.account_id);
            const result =  await isRequestChangeEmailValid(param, account, locale);

            if (result.response.status !== Response.Status.OK)
            {
                res.json(result.response);
                break;
            }

            //
            let response : Response.RequestChangeEmail;

            if (account.email === changeEmail)
            {
                response =
                {
                    status:  Response.Status.OK,
                    message: {general:R.text(R.EMAIL_CHANGED, locale)}
                };
                res.json(response);
            }

            else if (changeEmail === null)
            {
                // メールアドレスを削除する場合
                account.email = null;
                account.password = null;
                await AccountAgent.update(account);

                response =
                {
                    status:  Response.Status.OK,
                    message: {general:R.text(R.PASSWORD_SETTING_CENCELED, locale)}
                };
                res.json(response);
            }

            else if (account.password === null)
            {
                // パスワードが設定されていない場合
                const template = R.mail(R.NOTICE_SET_MAIL_ADDRESS, locale);
                const resultSendMail = await Utils.sendMail(template.subject, changeEmail, template.contents);

                if (resultSendMail)
                {
                    account.email = changeEmail;
                    await AccountAgent.update(account);

                    response =
                    {
                        status:  Response.Status.OK,
                        message: {general:R.text(R.EMAIL_CHANGED, locale)}
                    };
                }
                else
                {
                    response =
                    {
                        status:  Response.Status.FAILED,
                        message: {email:R.text(R.COULD_NOT_CHANGE_EMAIL, locale)}
                    };
                }

                res.json(response);
            }

            else
            {
                // パスワードが設定されている場合
                const changeId = Utils.createRandomText(32);
                const url = Utils.generateUrl('settings/account/email/change', changeId);
                const template = R.mail(R.NOTICE_CHANGE_MAIL_ADDRESS, locale);
                const contents = CommonUtils.formatString(template.contents, {url});
                const resultSendMail = await Utils.sendMail(template.subject, changeEmail, contents);

                if (resultSendMail)
//.........这里部分代码省略.........
开发者ID:nandai,项目名称:web-service-template,代码行数:101,代码来源:onRequestChangeEmail.ts

示例8: isChangePasswordValid

export async function isChangePasswordValid(param : Request.ChangePassword, myAccountId : number, locale : string) : Promise<ValidationResult>
{
    const log = slog.stepIn('SettingsApi', 'isChangePasswordValid');
    const response : Response.ChangePassword = {status:Response.Status.OK, message:{}};
    const {oldPassword, newPassword, confirm} = param;

    let account : Account = null;

    do
    {
        // パスワード検証
        const passwordResult = Validator.password({password:newPassword, confirm, canNull:true}, locale);

        if (passwordResult.status !== Response.Status.OK)
        {
            response.status =              passwordResult.status;
            response.message.newPassword = passwordResult.password;
            response.message.confirm =     passwordResult.confirm;
        }

        // アカウント存在検証
        account = await AccountAgent.find(myAccountId);

        if (account === null)
        {
            response.status = Response.Status.FAILED;
            response.message.general = R.text(R.ACCOUNT_NOT_FOUND, locale);
            break;
        }

        // メールアドレスが設定されているかどうか
        if (account.email === null)
        {
            response.status = Response.Status.FAILED;
            response.message.general = R.text(R.CANNOT_SET_PASSWORD, locale);
        }

        // パスワードを未設定にする場合は他に認証手段があるかどうか
        if (newPassword === null)
        {
            if (AccountAgent.canUnlink(account, 'email') === false)
            {
                response.status = Response.Status.FAILED;
                response.message.newPassword = R.text(R.CANNOT_NO_SET_PASSWORD, locale);
            }
        }

        // 現在のパスワードと現在のパスワードとして入力されたパスワードが一致するかどうか
        if (account.password !== null || oldPassword !== null)
        {
            const hashPassword = Utils.getHashPassword(account.email, oldPassword, Config.PASSWORD_SALT);

            if (hashPassword !== account.password)
            {
                response.status = Response.Status.FAILED;
                response.message.oldPassword = 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, account};
}
开发者ID:nandai,项目名称:web-service-template,代码行数:68,代码来源:onChangePassword.ts


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