當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript account-agent.update函數代碼示例

本文整理匯總了TypeScript中server/agents/account-agent.update函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript update函數的具體用法?TypeScript update怎麽用?TypeScript update使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了update函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: 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

示例3: onChangePassword

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

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

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

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

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

            // 更新
            const {account} = result;
            account.password = Utils.getHashPassword(account.email, param.newPassword, Config.PASSWORD_SALT);
            await AccountAgent.update(account);

            // 送信
            const data : Response.ChangePassword =
            {
                status:  Response.Status.OK,
                message: {general:R.text(R.PASSWORD_CHANGED, locale)}
            };
            res.json(data);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
開發者ID:nandai,項目名稱:web-service-template,代碼行數:52,代碼來源:onChangePassword.ts

示例4: onResetPassword

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

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

            // 検証
            const account = await AccountAgent.findByResetId(param.resetId);
            const result = isResetPasswordValid(param, account, locale);

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

            // 更新
            account.password = Utils.getHashPassword(account.email, param.password, Config.PASSWORD_SALT);
            account.reset_id = null;
            account.two_factor_auth = null;
            await AccountAgent.update(account);

            // 送信
            const data : Response.ResetPassword =
            {
                status:  Response.Status.OK,
                message: {general:R.text(R.PASSWORD_RESET, locale)}
            };
            res.json(data);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
開發者ID:nandai,項目名稱:web-service-template,代碼行數:51,代碼來源:onResetPassword.ts

示例5: onChangeEmail

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

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

            // 検証
            const account = await AccountAgent.findByChangeId(param.changeId);
            const result =  await isChangeEmailValid(param, account, locale);

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

            // メールアドレス設定(変更)
            account.email = account.change_email;
            account.password = Utils.getHashPassword(account.email, param.password, Config.PASSWORD_SALT);
            account.change_id = null;
            account.change_email = null;
            await AccountAgent.update(account);

            const response : Response.ChangeEmail =
            {
                status:  Response.Status.OK,
                message: {general:R.text(R.EMAIL_CHANGED, locale)}
            };
            res.json(response);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
開發者ID:nandai,項目名稱:web-service-template,代碼行數:50,代碼來源:onChangeEmail.ts

示例6: onJoin

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

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

            // 検証
            const account = await AccountAgent.findByInviteId(param.inviteId);
            const result = await isJoinValid(param, account, locale);

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

            // 更新
            account.password =  Utils.getHashPassword(account.email, param.password, Config.PASSWORD_SALT);
            account.signup_id = null;
            account.invite_id = null;
            await AccountAgent.update(account);

            // 送信
            const data : Response.Join =
            {
                status:  Response.Status.OK,
                message: {general:R.text(R.SIGNUP_COMPLETED, locale)}
            };
            res.json(data);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
開發者ID:nandai,項目名稱:web-service-template,代碼行數:50,代碼來源:onJoin.ts

示例7: 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

示例8: 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


注:本文中的server/agents/account-agent.update函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。