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


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

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


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

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

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

示例4: onSignupEmail

export async function onSignupEmail(req : express.Request, res : express.Response)
{
    const log = slog.stepIn('SignupApi', 'onSignupEmail');
    do
    {
        const locale = req.ext.locale;
        const param     : Request.SignupEmail = req.body;
        const condition : Request.SignupEmail =
        {
            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 alreadyExistsAccount = await AccountAgent.findByProviderId('email', param.email);
        const result = await isSignupEmailValid(param, alreadyExistsAccount, locale);

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

        process.nextTick(() =>
        {
            const hashPassword = Utils.getHashPassword(email, password, Config.PASSWORD_SALT);
            Email.verify(email, hashPassword, (_err, user) =>
            {
                req.ext.command = 'signup';
                req.user = user;
                Email.callback(req, res);
            });
        });
    }
    while (false);
    log.stepOut();
}
開發者ID:nandai,項目名稱:web-service-template,代碼行數:45,代碼來源:onSignupEmail.ts

示例5: onInvite

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

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

            // 検証
            const account = await AccountAgent.findByProviderId('email', param.email);
            const result =  await isInviteValid(param, account, locale);

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

            // 実行
            const response = await execInvite(param, locale);
            res.json(response);
        }
        while (false);
        log.stepOut();
    }
    catch (err) {Utils.internalServerError(err, res, log);}
}
開發者ID:nandai,項目名稱:web-service-template,代碼行數:39,代碼來源:onInvite.ts

示例6: isRequestChangeEmailValid

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

    do
    {
        if (email)
        {
            const alreadyExistsAccount = await AccountAgent.findByProviderId('email', email);
            const resultEmail = await Validator.email(email, myAccount.id, alreadyExistsAccount, locale);

            if (resultEmail.status !== Response.Status.OK)
            {
                response.status =        resultEmail.status;
                response.message.email = resultEmail.message;
            }
        }
        else
        {
            if (AccountAgent.canUnlink(myAccount, 'email') === false)
            {
                response.status = Response.Status.FAILED;
                response.message.email = R.text(R.CANNOT_EMPTY_EMAIL, 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,代碼行數:37,代碼來源:onRequestChangeEmail.ts


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