本文整理匯總了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);}
}
示例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);}
}
示例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);}
}
示例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);}
}
示例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);}
}
示例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);}
}
示例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);}
}
示例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);}
}
示例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);}
}
示例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);}
}