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. 有没有办法在没有.save()方法的猫鼬中定义模型?
- 3. 有没有办法在内联方法中使用let语句?
- 4. 有没有办法在终端中用特定名称替换IP地址?
- 5. 有没有办法让链接在OSX终端中可点击?
- 6. 有没有办法用HTMLAgilityPack替换带有文本节点的html节点?
- 7. 有没有办法在Textmate中从方法跳转到方法?
- 8. 有没有办法在vi中编辑最后的搜索/替换模式?
- 9. 有没有办法在JavaScript中模拟点击警报?
- 10. 有没有办法用itextsharp替换PDF文件中的文本?
- 11. 有没有办法在Django模型中创建依赖字段?
- 12. 有没有办法在swift 3中平滑对象/模型?
- 13. 有没有办法避免客户端的javascript方法暴露?
- 14. 有没有办法挂钩Java方法?
- 15. 有没有办法将MVC 3模型转换为Knockout View模型
- 16. 有没有办法定义在方法声明中两个泛型类型
- 17. 有没有办法替代View?
- 18. 有没有办法替代库类?
- 19. 有没有办法通过替换部分或全部类型参数来覆盖虚拟泛型方法?
- 20. 有没有办法在XBL中创建私有方法?
- 21. 有没有办法在XPATH 1上正确模拟替换函数?
- 22. 有没有办法在android中同时设置高度和换行内容?
- 23. 在YUI3中,有没有办法将模型重置为以前保存的值?
- 24. 对象没有方法'替换'
- 25. 有没有办法从WCF REST方法返回不同类型?
- 26. PHP:有没有办法获得方法的返回类型?
- 27. 有没有办法从方法返回匿名类型?
- 28. 有没有办法用rspec检查内部方法变量?
- 29. 有没有在Angular路由中替换CanNotActivate的好方法?
- 30. 有没有办法通过点击主页div来替换模态的内容div?
我会试一试,让你知道结果 – 2014-10-14 04:16:18