Node.js stormpath帐户的模板自定义数据
我可以拥有一个JSON模板,自动分配给Stormpath中每个新创建用户的自定义数据字段吗 目前,我正在尝试将JSON模板复制到postRegistrationHandler函数中的account.customData,但我正在努力正确地复制它 所以我有Node.js stormpath帐户的模板自定义数据,node.js,express,stormpath,Node.js,Express,Stormpath,我可以拥有一个JSON模板,自动分配给Stormpath中每个新创建用户的自定义数据字段吗 目前,我正在尝试将JSON模板复制到postRegistrationHandler函数中的account.customData,但我正在努力正确地复制它 所以我有 postRegistrationHandler: function (account, req, res, next) { console.log('User:', account.email, 'just registered!')
postRegistrationHandler: function (account, req, res, next) {
console.log('User:', account.email, 'just registered!');
writeCustomDataToAccount(account, customDataBlank);
next();
},
“customDataBlank”是服务器上的.json文件。然后
var writeCustomDataToAccount = function (account, customData) {
account.getCustomData(function (err, data) {
for (var field in customData) {
data[field] = customData[field];
}
data.save();
});
}
这看起来合理吗
编辑:
我现在能够比以前更好地复制JSON了,但我的问题仍然存在——我可以拥有一个JSON模板,自动分配给Stormpath中每个新创建用户的自定义数据字段吗?您的代码在我看来是正确的——我是express Stormpath库的作者。在
postRegistrationHandler
中,您的代码将自动为每个新创建的用户存储一些自定义数据
不过,我确实注意到有一件事是关闭的——如果您的文件在磁盘上,那么看起来您不会在任何地方加载它。我要做的是:
app.use(stormpath.init(app, {
postRegistrationHandler: function(account, req, res, next) {
console.log('User:', account.email, 'just registered!');
account.getCustomData(function(err, data) {
if (err) return next(err);
var dataToStore = require(customDataBlank); // this will load JSON from the file on disk
for (var field in require(customDataBlank)) {
data[field] = dataToStore[field];
}
data.save(function(err) {
if (err) return next(err);
next();
});
});
},
}));
您的代码在我看来是正确的--我是ExpressStormPath库的作者。在
postRegistrationHandler
中,您的代码将自动为每个新创建的用户存储一些自定义数据
不过,我确实注意到有一件事是关闭的——如果您的文件在磁盘上,那么看起来您不会在任何地方加载它。我要做的是:
app.use(stormpath.init(app, {
postRegistrationHandler: function(account, req, res, next) {
console.log('User:', account.email, 'just registered!');
account.getCustomData(function(err, data) {
if (err) return next(err);
var dataToStore = require(customDataBlank); // this will load JSON from the file on disk
for (var field in require(customDataBlank)) {
data[field] = dataToStore[field];
}
data.save(function(err) {
if (err) return next(err);
next();
});
});
},
}));
你好,Nic,这看起来是正确的-问题是您没有看到保存在帐户自定义数据对象中的数据吗?另外,我在Stormpath工作:)嗨,Nic,这看起来是正确的-问题是您没有看到保存在帐户自定义数据对象中的数据吗?另外,我在Stormpath工作:)嘿,Randall,希望你能回答这个:)就像你在这里做的所有其他Stormpath查询一样。我已经将json文件加载到一个变量中,然后使用它,但是您的方法可能会更好,并且可以防止在函数之外创建此变量:-/。我想现在我的问题是‘我可以指定一个JSON模板,Stormpath应用于为我的应用程序创建的每个用户吗?’我的意思是,这与我在postReg函数中编写模板没有太大区别,所以没什么大不了的。干杯,伙计!嘿,尼克,你现在不能这么做——这实际上是一个很好的建议!我会把这个传给我们的工程团队,看看他们怎么想=)嘿,Randall,我希望你能回答这个:)就像你在这里做的所有其他Stormpath查询一样。我已经将json文件加载到一个变量中,然后使用它,但是您的方法可能会更好,并且可以防止在函数之外创建此变量:-/。我想现在我的问题是‘我可以指定一个JSON模板,Stormpath应用于为我的应用程序创建的每个用户吗?’我的意思是,这与我在postReg函数中编写模板没有太大区别,所以没什么大不了的。干杯,伙计!嘿,尼克,你现在不能这么做——这实际上是一个很好的建议!我会把这个传给我们的工程团队,看看他们怎么想=)