本文整理匯總了TypeScript中server/libs/utils.getHashPassword函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getHashPassword函數的具體用法?TypeScript getHashPassword怎麽用?TypeScript getHashPassword使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getHashPassword函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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};
}
示例2: async
test.serial('パスワード変更の入力値検証 - メールアドレス以外に認証手段がある時はパスワードなしに変更できること', async (t) =>
{
const log = slog.stepIn('test', t['_test'].title);
let account : Account =
{
email: 'admin@example.com',
password: '12345678',
twitter: 'twitter'
};
account.password = Utils.getHashPassword(account.email, account.password, Config.PASSWORD_SALT);
account = await AccountAgent.add(account);
const param : Request.ChangePassword =
{
oldPassword: '12345678',
newPassword: null,
confirm: null,
};
const result = await isChangePasswordValid(param, account.id, locale);
const {status} = result.response;
t.is(status, Response.Status.OK);
await AccountAgent.remove(account.id);
log.stepOut();
});
示例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:
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);
});
});
示例5: 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);}
}
示例6: 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);}
}
示例7: 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);}
}
示例8: 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);}
}
示例9: 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};
}