當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。