我正在使用FatFractal JavaScript SDK并在我的FFDL文件中声明了服务器扩展,如下所示:
CREATE EXTENSION /ChangePassword AS javascript:require('scripts/UserAdministration').changePassword();
我正在创建服务器扩展以允许用户更改其登录密码。从我的客户端应用程序,我想将一个简单的对象传递给/ChangePassword
,其中包含登录用户的用户名,当前(旧)密码和新的所需密码。假设我已经填充了所述对象,那么我将如何A)将客户端应用程序的对象传递给服务器扩展,B)获取服务器扩展中传递的对象的句柄,并且C)返回确认对象(最好)或消息一旦更改完成,从服务器扩展到客户端应用程序?
FFDL:
CREATE OBJECTTYPE ChangePasswordRequest (userName STRING, oldPassword STRING, newPassword STRING)
CREATE COLLECTION /ChangePasswordRequest OBJECTTYPE ChangePasswordRequest
客户端应用程序JS代码:
...
function ChangePassInfo() {
this.userName = null;
this.currentPassword = null;
this.newPassword = null;
return this;
}
...
function changePassword() {
var uname = ff.loggedInUser().userName;
var oldPass = $("#input-curr-pass").val();
var newPass = $("#input-new-pass").val();
var requestInfo = new ChangePassInfo();
requestInfo.userName = uname;
requestInfo.currentPassword = oldPass;
requestInfo.newPassword = newPass;
// pass 'requestInfo' to 'ChangePassword' extension
// acquire handle to confirmation object/message returned from 'ChangePassword'
...
}
服务器扩展JS代码:
var ff = require('ffef/FatFractal');
...
function ChangePasswordRequest() {
this.clazz = 'ChangePasswordRequest';
this.createdBy = 'system';
this.userName = null;
this.oldPassword = null;
this.newPassword = null;
return this;
}
...
function changePassword() {
var changePassReq; // instance of a 'ChangePasswordRequest' object
// acquire handle to 'requestInfo' passed from client application to populate 'changePassReq'
...
// return a confirmation message or copy of 'changePassReq' to client application
}
...
exports.changePassword = changePassword;
评论的部分是我想要解决的问题领域。一旦解决了这些问题,我应该能够填写其余的实现。谢谢!
答案 0 :(得分:2)
让我们从后端开始吧。假设某个对象已发布到扩展名,以下是您在函数中检索它的方法:
var ff = require('ffef/FatFractal'); // FatFractal module
var data = ff.getExtensionRequestData(); // Get request data
var member = data.httpContent.member // Get 'obj' member of passed object
好吧,现在你已经做了一些事情,想要回复一些东西,这就是你如何做到的:
var r = ff.response(); // Get response object, and populate
r.result = { member: "Something", otherMember: false, yaMember: 42 };
r.responseCode = "200";
r.statusMessage = "This message is useful";
r.mimeType = "application/json";
最后,到客户端。以下是将对象发布到扩展名的方法:
var ff = new FatFractal();
// ...
ff.postObjToExtension({ member: "derp" }, "/yourExtension", ... );
希望澄清事情!