brian71us
RTC Expired
Posts: 15
|
|
« on: June 01, 2017, 10:12:16 PM » |
|
Hello,
I am working on a server that uses XML-RPC for remote procedure calls as shown below:
this.validateLogin = function(user, company, password) { console.log(JSON.toString(user) + ", " + JSON.toString(company) + ", " + password); xmlrpc.callMethod('login', [{ User: user, Company: company, Password: password }]).then(function(response){ console.log(response); if (response === 'OK') { return true; } else if (response === 'Fail') { return false; }; }, function(err){ console.log("Error validating login: " + JSON.stringify(err)); }); };
Password is a string. User and Company are JavaScript objects.
What I receive on the server is show below.
'(Oid={8D03643A-CAEA-4A21-8563-3E0890E30634}; UserName=Zachary Cobb; CertificationNumber=OSHA-CERT007; Companies=(Oid={D014A27E-0003-4A5D-8BD7-E37A772DEEDC}; Name=Remarkable Scales & Service; $$hashKey=object:18); $$hashKey=object:6)'
The TJSONObject.ParseJSONValue() method returns nil when I pass this string to it.
The only way that I can get this all to work properly is to stringify the objects.
this.validateLogin = function(user, company, password) { console.log(JSON.toString(user) + ", " + JSON.toString(company) + ", " + password); xmlrpc.callMethod('login', [{ User: JSON.stringify(user), Company: JSON.stringify(company), Password: password }]).then(function(response){ console.log(response); if (response === 'OK') { return true; } else if (response === 'Fail') { return false; }; }, function(err){ console.log("Error validating login: " + JSON.stringify(err)); }); };
Is there a way to handle this without calling stringify for every object?
Here is the current implementation of the function.
procedure TUserModule.loginExecute(Sender: TRtcConnection; Param: TRtcFunctionInfo; Result: TRtcValue); var Company: TJSONObject; User: TJSONObject; Password: String; Parameter: String; begin // Get the parameters Parameter := Param.asString['User'];
User := TJSONObject.ParseJSONValue(Parameter) as TJSONObject;
Company := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(Param.asString['Company']),0) as TJSONObject; Password := Param.asString['Password'];
if ValidatePassword(User.Values['Oid'].Value, Password) then Result.asString := 'OK' else Result.asString := 'Fail'; end;
|