sails.helpers功能来自默认的sails web应用程序
我很好奇sails.helpers.x.y()函数来自sails附带的示例Web应用程序。
运行sails new test-project
后,选择Web应用程序并环顾四周,我注意到许多文件正在调用像sails.helpers.passwords.hashPassword()
这样的函数。
然而,当查看helpers
文件夹时,唯一的文件是send-template-email
,没有任何类似哈希密码的功能。
我已经阅读了关于sails辅助函数here的文档,它没有提到任何默认的辅助函数,比如hashPassword。我也经历了vscode中的调试器,发现确实定义了sails.helpers.passwords.hashpassword()
,但是当我搜索源代码时,我无法在任何地方找到它。
有谁知道这些助手来自哪里?
作为参考,我调试以获取hashPassword()
调用的代码部分位于signup.js
:
var newUserRecord = await User.create(_.extend({
emailAddress: newEmailAddress,
password: await sails.helpers.passwords.hashPassword(inputs.password),
fullName: inputs.fullName,
tosAcceptedByIp: this.req.ip
}, sails.config.custom.verifyEmailAddresses? {
emailProofToken: await sails.helpers.strings.random('url-friendly'),
emailProofTokenExpiresAt: Date.now() + sails.config.custom.emailProofTokenTTL,
emailStatus: 'unconfirmed'
}:{}))
回答如下:
它们来自sails-hook-organics包,请在这里查看密码方法,https://github/sailshq/sails-hook-organics/blob/a27db6c93e7333f5036a54ceb13a2e3b3fa0ae26/OTHER-USEFUL-METHODS.md