本文整理匯總了TypeScript中server/libs/r.text函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript text函數的具體用法?TypeScript text怎麽用?TypeScript text使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了text函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: accountName
export function accountName(aAccountName : string, locale : string) : ValidationResult
{
let status = Response.Status.FAILED;
let message : string;
const _accountName = aAccountName || '';
do
{
const min = 1;
const max = 20;
if (_accountName !== _accountName.trim())
{
message = R.text(R.CANNOT_ENTER_ACCOUNT_NAME_BEFORE_AFTER_SPACE, locale);
break;
}
const len = _accountName.length;
if (len < min || max < len)
{
message = R.text(R.ACCOUNT_NAME_TOO_SHORT_OR_TOO_LONG, locale, {min, max});
break;
}
status = Response.Status.OK;
}
while (false);
return ({status, message});
}
示例2: email
export async function email(aEmail : string, accountId : number, alreadyExistsAccount : Account, locale : string) : Promise<ValidationResult>
{
const log = slog.stepIn('Validator', 'email');
let status = Response.Status.FAILED;
let message : string;
do
{
if (! aEmail || nodeValidator.isEmail(aEmail) === false)
{
message = R.text(R.INVALID_EMAIL, locale);
break;
}
if (alreadyExistsAccount && alreadyExistsAccount.id !== accountId)
{
message = R.text(R.ALREADY_EXISTS_EMAIL, locale);
break;
}
const hostname = aEmail.split('@')[1];
if (await Utils.existsHost(hostname) === false)
{
message = R.text(R.INVALID_EMAIL, locale);
break;
}
status = Response.Status.OK;
}
while (false);
log.stepOut();
return {status, message};
}
示例3: execInvite
/**
* 実行
*/
async function execInvite(param : Request.Invite, locale : string) : Promise<Response.Invite>
{
const log = slog.stepIn('SettingsApi', 'execInvite');
const response : Response.Invite = {status:Response.Status.FAILED, message:{}};
const {email} = param;
const invite_id = Utils.createRandomText(32);
const url = Utils.generateUrl('join', invite_id);
const template = R.mail(R.NOTICE_INVITE, locale);
const contents = CommonUtils.formatString(template.contents, {url});
const result = await Utils.sendMail(template.subject, email, contents);
if (result)
{
response.status = Response.Status.OK;
response.message.general = R.text(R.INVITE_MAIL_SENDED, locale);
const name = email.substr(0, email.indexOf('@'));
const account : Account = {name, email, invite_id};
await AccountAgent.add(account);
}
else
{
response.message.email = R.text(R.COULD_NOT_SEND_INVITE_MAIL, locale);
}
log.stepOut();
return response;
}
示例4: isConfirmSignupEmailValid
export function isConfirmSignupEmailValid(param : Request.ConfirmSignupEmail, account : Account, locale : string) : ValidationResult
{
const log = slog.stepIn('SignupApi', 'isConfirmSignupEmailValid');
const response : Response.ConfirmSignupEmail = {status:Response.Status.OK, message:{}};
do
{
if (account === null)
{
// サインアップの確認畫麵でサインアップを完了させた後、再度サインアップを完了させようとした場合にここに到達する想定。
// サインアップIDで該當するアカウントがないということが必ずしもサインアップ済みを意味するわけではないが、
// 第三者が直接このAPIをコールするなど、想定以外のケースでなければありえないので、登録済みというメッセージでOK。
response.status = Response.Status.FAILED;
response.message.general = R.text(R.ALREADY_SIGNUP, locale);
break;
}
const hashPassword = Utils.getHashPassword(account.email, param.password, Config.PASSWORD_SALT);
if (account.password !== hashPassword)
{
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};
}
示例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: userName
export function userName(aUserName : string, accountId : number, alreadyExistsAccount : Account, locale : string) : ValidationResult
{
let status = Response.Status.FAILED;
let message : string;
do
{
const min = 0;
const max = 20;
if (! aUserName)
{
status = Response.Status.OK;
break;
}
if (aUserName !== aUserName.trim())
{
message = R.text(R.CANNOT_ENTER_USER_NAME_BEFORE_AFTER_SPACE, locale);
break;
}
const len = aUserName.length;
if (len < min || max < len)
{
message = R.text(R.USER_NAME_TOO_LONG, locale, {min, max});
break;
}
if (aUserName && isNaN(Number(aUserName)) === false)
{
message = R.text(R.CANNOT_ENTER_USER_NAME_ONLY_NUMBERS, locale);
break;
}
if (aUserName.match(/^[0-9a-zA-Z-_]+$/) === null)
{
message = R.text(R.ENTER_ALPHABETICAL_NUMBER_BAR, locale);
break;
}
if (alreadyExistsAccount && alreadyExistsAccount.id !== accountId)
{
message = R.text(R.ALREADY_USE_USER_NAME, locale);
break;
}
status = Response.Status.OK;
}
while (false);
return ({status, message});
}
示例7: password
export function password(args : {password : string, confirm? : string, canNull? : boolean}, locale : string)
{
const {confirm, canNull} = args;
const _password = args.password;
const result =
{
status: Response.Status.OK,
password: null as string,
confirm: null as string
};
do
{
const min = 8;
const max = 16;
if (_password === null)
{
if (confirm === undefined || canNull !== true)
{
result.status = Response.Status.FAILED;
result.password = R.text(R.PASSWORD_TOO_SHORT_OR_TOO_LONG, locale, {min, max});
}
}
else
{
const len = _password.length;
if (len < min || max < len)
{
result.status = Response.Status.FAILED;
result.password = R.text(R.PASSWORD_TOO_SHORT_OR_TOO_LONG, locale, {min, max});
}
else if (_password.match(/^[0-9a-zA-Z@]+$/) === null)
{
result.status = Response.Status.FAILED;
result.password = R.text(R.ENTER_ALPHABETICAL_NUMBER, locale);
}
}
// 確認用パスワードが一致するか
if (confirm !== undefined && _password !== confirm)
{
result.status = Response.Status.FAILED;
result.confirm = R.text(R.MISMATCH_PASSWORD, locale);
}
}
while (false);
return (result);
}
示例8: 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};
}
示例9: 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);}
}
示例10: 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);}
}