本文整理汇总了TypeScript中server/libs/utils.internalServerError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript internalServerError函数的具体用法?TypeScript internalServerError怎么用?TypeScript internalServerError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了internalServerError函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: onGetUser
export async function onGetUser(req : express.Request, res : express.Response)
{
const log = slog.stepIn('UserApi', 'onGetUser');
try
{
do
{
const locale = req.ext.locale;
const param : Request.GetUser = req.query;
const condition : Request.GetUser =
{
id: ['any', null, true] as any
};
if (Utils.existsParameters(param, condition) === false)
{
res.ext.badRequest(locale);
break;
}
const data = await getUser(param, req);
res.json(data);
}
while (false);
log.stepOut();
}
catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:28,代码来源:onGetUser.ts
示例3: 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
示例4: onGetUserList
export async function onGetUserList(_req : express.Request, res : express.Response)
{
const log = slog.stepIn('UserApi', 'onGetUserList');
try
{
const data = await getUserList();
res.json(data);
log.stepOut();
}
catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:11,代码来源:onGetUserList.ts
示例5: 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
示例6: onCheckUserName
export async function onCheckUserName(req : express.Request, res : express.Response)
{
const log = slog.stepIn('SettingsApi', 'onCheckUserName');
try
{
do
{
const locale = req.ext.locale;
const param : Request.CheckUserName = req.query;
const condition : Request.CheckUserName =
{
userName: ['string', null, true] as any
};
if (Utils.existsParameters(param, condition) === false)
{
res.ext.badRequest(locale);
break;
}
const {userName} = param;
// 検証
const session : Session = req.ext.session;
const alreadyExistsAccount = await AccountAgent.findByUserName(userName);
const result = Validator.userName(userName, session.account_id, alreadyExistsAccount, locale);
let response : Response.CheckUserName;
if (result.status !== Response.Status.OK)
{
response =
{
status: result.status,
message: {userName:result.message}
};
res.json(response);
break;
}
const message = (userName ? R.text(R.CAN_USE_USER_NAME, locale) : '');
response =
{
status: Response.Status.OK,
message: {userName:message}
};
res.json(response);
}
while (false);
log.stepOut();
}
catch (err) {Utils.internalServerError(err, res, log);}
}
开发者ID:nandai,项目名称:web-service-template,代码行数:52,代码来源:onCheckUserName.ts
示例7: 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
示例8: 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
示例9: 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
示例10: 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
注:本文中的server/libs/utils.internalServerError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论