kenyee / java-ddp-client

A DDP client written in java for the Meteor framework (https://github.com/meteor/meteor)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Login funciton

opened this issue · comments

Hello, I try to use your login funtion ddp.call("login" ....
final HashMap auth = new HashMap();
auth.put("email", "myMailAdress");
auth.put("password", "myMailPassword");
Object[] methodArgs = new Object[1];
methodArgs[0] = auth;

But I have an error :
Server log 🎱
Exception while invoking method 'login' Error: Match error: Unknown key in field email
I20150317-18:10:55.115(1)? at packages/check/match.js:299:1
I20150317-18:10:55.115(1)? at Function..each..forEach (packages/underscore/underscore.js:113:1)
I20150317-18:10:55.115(1)? at checkSubtree (packages/check/match.js:290:1)
I20150317-18:10:55.115(1)? at check (packages/check/match.js:32:1)
I20150317-18:10:55.115(1)? at [object Object].Accounts.registerLoginHandler.check.user (packages/accounts-password/password_server.js:144:1)
I20150317-18:10:55.115(1)? at packages/accounts-base/accounts_server.js:383:1
I20150317-18:10:55.115(1)? at tryLoginMethod (packages/accounts-base/accounts_server.js:186:1)
I20150317-18:10:55.115(1)? at runLoginHandlers (packages/accounts-base/accounts_server.js:380:1)
I20150317-18:10:55.115(1)? at [object Object].Meteor.methods.login (packages/accounts-base/accounts_server.js:434:1)
I20150317-18:10:55.115(1)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599:1)
I20150317-18:10:55.116(1)? Sanitized and reported to the client as: Match failed [400]

Can you help me ?

commented

Hi,
I am going to assume you are using the in built Meteor's login function.
If that is so, then the below structure should work for you (as it did for me):

    Object[] params = new Object[1];
    Map<String, Object> userInformation = new LinkedHashMap<String, Object>();
    userInformation.put("password", password);
    Map<String, Object> userUsername = new HashMap<String, Object>();
    userUsername.put("username", username);
    userInformation.put("user", userUsername);

    params[0] = userInformation;    

    ddpClient.call("login", params, yourListenerHere);

//Mine is "ddpClient.call("login", params, new LoginListener());"

commented

Oh. Do note kenyee's code does not handle the subscription received message. I am working on building up his this code base to handle that (Including reconnection as well). Its here
https://github.com/tlkiong/java-ddp-client

tlkiong: please do a pull request when you've added that and I'll merge it in...not sure what you mean by the subscription received msg because the android ddp example handles subscriptions w/o problems.

duxmaxime: the unit tests have examples of all the functionality...you should be looking them if you get stuck and if you do get stuck, put it in a unit test for me to look at.

commented

Well, I am not sure what went wrong.
But when I subscribed to a meteor server using this current code, I do not receive any reply on the "onResult" in the listener.
On further checking, the messaged type that was passed in is "changed" instead of "ready". So, I am adding that in. And, its defined as LISTENER_ID = 'id'. However, on the subscribed, the meteor server does not return that listener id that we pass up to them. In fact, it is lost unless handled. the id that is returned is userId (once authenticated)

When you call subscribe, that method returns a subscription ID. You can use this to unsubscribe. I've updated the code to show this.

For login, look at the android-ddp-client library for an example.