• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript onChangePassword.isChangePasswordValid函数代码示例发布时间:2022-05-25
下一篇:
TypeScript account-agent.remove函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap