Login and email address in Parse Android

I need to implement this, I want to double check both email and username. So I thought that if I make a normal query and double checkthen it works, but it was an error because when I tried to check the password field it was the problem.

I saw this answer from the parsing blog, but this is not what I want. I think it's possible.

Link

+3


source to share


2 answers


Based on your original question and comments, here's what I suggest. It seems that you want the user to enter their email address or username and their password to login. Your database requires both of these fields to be unique.

I still don't understand why you are using a separate User table if you have Parse, but let's still assume that you are just using a Parse User object.

In Parse, you want to register a user in a standard way.

ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email@example.com");

user.signUpInBackground(new SignUpCallback() {
  ...
});

      



Parse will automatically check that you have a unique username and username .

Then, to login using either your username or email address, you will need to write a little query before login. This will replace the email with the username and then launch with that username and password entered by the user.

// If the entered username has an @, assume it is an email
String username = "bob@example.com";

if (username.indexOf("@")) {
  ParseQuery<ParseUser> query = ParseUser.getQuery();
  query.whereEqualTo("email", username);
  query.getFirstInBackground(new GetCallback<ParseObject>() {
      public void done(ParseObject object, ParseException e) {
          if (object == null) {
              Log.d("score", "The getFirst request failed.");
          } else {
               String actualUsername = object.get("username");
               ParseUser.logInInBackground(actualusername, "showmethemoney", new LogInCallback() {
                 ...
               });
          }
      }
   });
}

      

+8


source


The password will not be saved as clear text, so you cannot filter it in the request.

To log in, you really need to use one of the provided logIn methods , which also handle the session for you. They only support one username (which can be emailed if you want), to which you can also add an email (via the ParseUser

email field ).



Requiring both username and email asks the question: can another user sign up with the same username but with a different email address? I doubt this is desirable, so it's probably best to stick with the standard approach.

0


source







All Articles