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