2

我正在使用 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;

评论部分是我要解决的问题领域。一旦这些都解决了,我应该能够填写其余的实现。谢谢!

4

1 回答 1

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", ... );

希望能澄清事情!

于 2013-04-06T00:17:49.607 回答