2
A
回答
0
您需要声明一个新模型。然后,之后,手动添加base
属性以使其从内置User模型继承。
/common/models/custom-user.json
{
"name": "customUser",
"base": "User",
"options": {
"idInjection": false,
"postgresql": {
"schema": "public",
"table": "user"
}
},
"dataSource": "mypostgresDS",
"properties": {
"id": {
"type": "number",
"postgresql": {
"columnName": "id",
"dataType": "integer"
}
}
...
...
}
}
然后你就可以在
/common/models/custom-user.js
module.exports = function (customUser) {
// avoid looking for properties that your new model doesn't have
var excludedProperties = [
'realm',
'emailVerified',
'verificationToken',
'credentials',
'challenges',
'lastUpdated',
'created'
];
// Remove the properties from base User model that doesn't have mapped columns
excludedProperties.forEach(function (p) {
delete customUser.definition.rawProperties[p];
delete customUser.definition.properties[p];
delete customUser.prototype[p];
});
customUser.prototype.createAccessToken = function (ttl, cb) {
var user = this;
if (ttl === undefined) ttl = 259200;
var timenow = new Date().toISOString();
console.log('ttl will be ', ttl, ' current time is ' + timenow);
user.accessTokens.create({
ttl: ttl
}, cb);
};
customUser.prototype.checkPassword = function (password, stored_hash) {
var user = this;
console.log('I will overwrite this check to always return true');
return true;
};
});
覆盖内置路线
相关问题
- 1. 有没有办法替换C++中的方法中的函数
- 2. 有没有办法在AngularJS中转换类似于此Jquery方法的模型?
- 3. 有没有办法用更新的原始模型替换克隆模型?
- 4. 有没有办法嵌套sed替换?
- 5. 有没有办法在没有.save()方法的猫鼬中定义模型?
- 6. 在YUI3模型中,有没有办法重置为默认值?
- 7. 有没有办法在Perl中模拟内置的require函数?
- 8. 有没有办法一次替换整个XML节点?
- 9. 有没有办法在内联方法中使用let语句?
- 10. 有没有办法在javascript中换行?
- 11. 有没有办法在ES6类上有内部方法?
- 12. 有没有办法在终端中用特定名称替换IP地址?
- 13. 有没有办法在Intellij Idea中用另一个替换Class?
- 14. 有没有办法在ServiceStack中禁用默认端点?
- 15. 有没有办法让链接在OSX终端中可点击?
- 16. 有没有办法用HTMLAgilityPack替换带有文本节点的html节点?
- 17. 有没有办法在Textmate中从方法跳转到方法?
- 18. 有没有办法在ruby脚本中设置客户端hello?
- 19. 有没有办法在vi中编辑最后的搜索/替换模式?
- 20. SSRS报告,有没有办法根据配置切换模板?
- 21. 有没有办法在haskell中转换函数类型?
- 22. 有没有办法在JavaScript中模拟点击警报?
- 23. 有没有办法在Geddy模型中定义虚拟域?
- 24. 有没有办法在Django模型中创建依赖字段?
- 25. 有没有办法在函数中定义模型字段?
- 26. 有没有办法在swift 3中平滑对象/模型?
- 27. 有没有办法在余烬模型中执行回滚?
- 28. 有没有办法避免客户端的javascript方法暴露?
- 29. 有没有办法不公开一个方法到客户端?
- 30. 有没有办法用itextsharp替换PDF文件中的文本?
我会试一试,让你知道结果 – 2014-10-14 04:16:18