Start a new topic

Post email in the user creation request

Hello,



I am trying to create a user from the android application. The only API I can find is

User.createBlocking(username, password);



Because I want to enforce email verification, I need to supply the email in the request. I am doing something like that



Client kinveyClient = new Client.Builder(KINVEY_APP_KEY, KINVEY_APP_SECRET, context).build();

User kinveyUser = kinveyClient.user();

kinveyUser.put("email", "address@domain.com");

kinveyUser.createBlocking(username, password).execute();



But I am receiving an error indicating that no email is supplied. I can't find any other way to insert the email address in the request. Does anyone know how?



Thanks in advance.

So two things:



first, there is also an asynchronous create, which you can use as well. It will take a username, password, and `KinveyUserCallback`. This method will spawn a thread, execute the request, and then call the appropriate methods in that `KinveyUserCallback` object after the request has been completed. To do this, instead of:



User kinveyUser = kinveyClient.user();



you can do:



AsyncUser kinveyUser = kinveyClient.user();



Or, you can just access it directly through:



kinveyClient.user().create(...);







And finally, what you are doing looks like it should work. Can you open up https://console.kinvey.com/addons/users and double check that the email is not there?



As a quick test I did this, and it works:



AsyncUser myUser = getClient().user();

myUser.put("email", "ed@kinvey.com");



myUser.create("emailtest", "emailtest", new KinveyUserCallback() {

@Override

public void onSuccess(User result) {

preload();//To change body of implemented methods use File | Settings | File Templates.

}



@Override

public void onFailure(Throwable error) {

Util.Error(Contentviewr.this, error); //To change body of implemented methods use File | Settings | File Templates.

}

});

Hi Edward



It is not working, email address is not sent when creating user.

If "Enforce email verification" is turned on, I get 400 response code Bad Request



{"error":"MissingRequestParameter","description":"A required parameter is missing from the request","debug":"Email Verification is required for this app, but an email address was not provided for this user. Please try again and include an email address in the request."}



This is in response to Edward's answer.



I have tried your method with and without email verification enforcement.

It does not work with email verification enforced. Possibly because of my findings without email verification enforced.



I have also found that the Kinvey Sign Up sample also fails to do this.

I had to create a user and then update the user in the onSuccess method.



public static final String KINVEY_USERNAME = "username";

public static final String KINVEY_USER_EMAIL = "email";

public static final String KINVEY_USER_FIRST_NAME = "first_name";

public static final String KIVEY_USER_LAST_NAME = "last_name";



public void processSignup() {

Toast.makeText(this, "Creating user...", Toast.LENGTH_SHORT).show();

mKinveyClient.user().put(Consts.KINVEY_USER_EMAIL,

mEditEmailAddress.getText().toString());

mKinveyClient.user().put(Consts.KINVEY_USER_FIRST_NAME,

mEditFirstName.getText().toString());

mKinveyClient.user().put(Consts.KIVEY_USER_LAST_NAME,

mEditLastName.getText().toString());

mKinveyClient.user().create(mEditEmailAddress.getText().toString(),

mEditPassword.getText().toString(), new KinveyUserCallback() {

public void onFailure(Throwable t) {

CharSequence text = "Could not sign up -> " + t.getMessage();

Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();

Log.e(TAG, "Sign-up error", t);

}



@SuppressWarnings("rawtypes")

public void onSuccess(User u) {



mKinveyClient.user().update(new KinveyUserCallback() {

@Override

public void onSuccess(User u) {

CharSequence text = "Welcome, "

+ u.get(Consts.KINVEY_USER_FIRST_NAME)

+ ". Your account has been registered.

Please login to confirm your credentials.";

Log.d(TAG, text.toString());

Toast.makeText(getApplicationContext(), text,

Toast.LENGTH_LONG).show();

startActivity(new Intent(mContext, LoginActivity.class)

.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK));

finish();

}

@Override

public void onFailure(Throwable t) {

Log.e(TAG, "Failed to update user.");

}

});

}

});

}



If I move the code from the onSuccess() of the update callback and move it to the onSuccess() of the create callback, I get null for the user first_name parameter. I had to add the update call in order to get the additional parameters saved to the User class. So I can only get the additional info, including the required email, saved to the user after it is created and then updated.



The problem is that the email is not included in the initial creation request and I get the following error.

08-20 10:10:35.818: E/LoginActivity(11041): Sign-up error

08-20 10:10:35.818: E/LoginActivity(11041): com.kinvey.java.core.KinveyJsonResponseException: MissingRequestParameter

08-20 10:10:35.818: E/LoginActivity(11041): A required parameter is missing from the request

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.java.auth.KinveyAuthRequest.executeUnparsed(KinveyAuthRequest.java:204)

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.java.auth.KinveyAuthRequest.execute(KinveyAuthRequest.java:208)

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.java.User$LoginRequest.execute(User.java:590)

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.android.AbstractAsyncUser$Create.executeAsync(AbstractAsyncUser.java:856)

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.android.AbstractAsyncUser$Create.executeAsync(AbstractAsyncUser.java:844)

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.android.AsyncClientRequest.doInBackground(AsyncClientRequest.java:71)

08-20 10:10:35.818: E/LoginActivity(11041): at android.os.AsyncTask$2.call(AsyncTask.java:288)

08-20 10:10:35.818: E/LoginActivity(11041): at java.util.concurrent.FutureTask.run(FutureTask.java:237)

08-20 10:10:35.818: E/LoginActivity(11041): at com.kinvey.android.AsyncClientRequest$KinveySerialExecutor$1.run(AsyncClientRequest.java:145)

08-20 10:10:35.818: E/LoginActivity(11041): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

08-20 10:10:35.818: E/LoginActivity(11041): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

08-20 10:10:35.818: E/LoginActivity(11041): at java.lang.Thread.run(Thread.java:841)



Again, the above code works when email verification is NOT enforced.

How can I edit the creation request to include the email parameter?





I can confirm that automatic email validation is not working for the Android API 2.6.15.

No solution on this since January??
Hey-



Sorry for the delay in getting a response for this ticket. I have added the item to the backlog, and will try to get it into the next release.



In the meantime, as a workaround until I get the next version of the library out, you can manually trigger email verification-- I know this isn't ideal, but after a successful creation you can add the "email", call user.update(), and then call user().sendVerificationEmail().

1 person likes this
Login or Signup to post a comment