Question

I am new learner to implement the Parse user data mgt. I would like to resend email verification. After researched, I got an answer that

"You can "update" the email field on their User object with the same current email value and save again. That will trigger a new verification email."

How to do it?

Was it helpful?

Solution

Note that you can only modify the properties of a ParseUser for the one currently logged in for security reasons. Also don't forget to call one of the save methods on the user which your code is missing in your question.

ParseUser user = ParseUser.getCurrentUser();
user.setEmail(user.getEmail());
user.saveInBackground();

From the docs

Specifically, you are not able to invoke any of the save or delete type methods unless the ParseUser was obtained using an authenticated method, like logIn or signUp. This ensures that only the user can alter their own data.

So you don't need to "query" for the user as the user should already be logged in.

However, if you're doing this when a user is not logged in or globally, you may need to look at using cloud functions that allow administrative features.

For that you can refer to this which refers to cloud code. I've never used that part of Parse so I can't help much there if that's what you need.


Just to add to this great answer.

If you're new to Android/Parse, it's a good opportunity to also learn how to do it "in the background - making the user wait". So that's .saveInBackground.

private void resendEmail()
  {
  ParseUser user = ParseUser.getCurrentUser();
  user.setEmail(user.getEmail());

  ... here, bring up a message saying 'we're contacting the cloud!'

  user.saveInBackground(new SaveCallback()
  {
  public void done(ParseException e)
    {
    ... here, get rid of that message

    if (e == null)
      {
      Utils.Log("resendEmail no problem.");

      ... here, bring up a message like...
      String un = ParseUser.getCurrentUser().getUsername();
      "We have resent the validation email to " +un +". Please check your email!"
      }
    else
      {
      int errCodeSimple = e.getCode();
      Utils.Log(", some problem: " + errCodeSimple);

      ... here, bring up a message like...
      "We could not reach the internet! Try again later!"
      }
    }
  });

  }

Finally here's an amazing related trick in Android. When you create an account you'll want to check if it's a "valid-looking" email. This takes 18,000 lines of code in iOS but only one line of code in Android.

maybeEmail = emailField.getText().toString();

if (!android.util.Patterns.EMAIL_ADDRESS.matcher(maybeEmail).matches())
  {
  userAlert("Please a valid email, buddy!!!");
  return;
  }

Hope it helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top