How to check if Username/Email already exists android parse - android

I've searched everywhere but haven't found anything about how to check if a username/email address in the parse database is taken. I've found some answers on the internet on parse.com forums but they weren't clear.
Thanks if you could help.
If this has an answer somewhere, then please comment instead of marking so I can delete it.

I think this will do what you need if I understand your question correctly:
final ParseQuery<ParseUser> emailQuery = ParseUser.getQuery();
emailQuery.whereEqualTo("email", emailAddress);
final ParseQuery<ParseUser> usernameQuery = ParseUser.getQuery();
usernameQuery.whereEqualTo("email", username);
List<ParseQuery> queries = new ArrayList<>();
queries.add(emailQuery);
queries.add(usernameQuery);
final ParseQuery<ParseUser> query = ParseQuery.or(queries);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> results, ParseException e) {
// results has the list of users that match either the email address or username
}
});
https://www.parse.com/docs/android/guide#queries-compound-queries
Or you could do it this way:
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// yippee!!
} else {
switch (e.getCode()) {
case ParseException.USERNAME_TAKEN: {
// report error
break;
}
case ParseException.EMAIL_TAKEN: {
// report error
break;
}
default: {
// Something else went wrong
}
}
}
}
});

Try this to check your data in parse. I hope this will helpful for you.
// this is create query of your parse table
ParseQuery<ParseObject> query = new ParseQuery<>(your prars tableName);
query.whereEqualTo(YourParseColumeNameEmail, yourEmail);
query.whereEqualTo(YourParseColumeNamePassword, yourPassword);
// this is for doing in background
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
if (scoreList.size() == 0) {
// if there is no data like your email and password then it,s come here
} else {
// if there is data like your email and password then it,s come here
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});

Related

Using Parse get All User data

I use parse AnyPhone for Login using mobile number and after successfully login (OTP verification), i want to get all parse user from User table for that i used bellow query but i only get Login user Data not all. Thanks in Advance.
ArrayList<String> Email = new ArrayList<String>();
Email.add("test2#gmail.com");
Email.add("test#g.com");
Email.add("test#gmail.com");
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereContainedIn("email", Email);
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if(e==null){
Log.i("Size",""+objects.size());
}
}
});
void getAllParseUser() {
ParseUser user = ParseUser.getCurrentUser();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo(ParseTableConstants.OBJECT_ID, user.getObjectId());
progressBar.showProgress();
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
insertData(objects);
} else {
// Something went wrong.
progressBar.hideProgress();
}
}
});
}
This code will give you all parse user
I solved My Problem by setting ACL in javascript File.Now i am getting all the Users.
var acl = new Parse.ACL();
// public can read
acl.setPublicReadAccess( true );
// public cannot write
acl.setPublicWriteAccess( false );
// user can read data
acl.setReadAccess( user.id, true );
// user can write data
acl.setWriteAccess( user.id, false );
user.setACL(acl);
user.save();

Parse does't do query on android

I'm using Parse in a android, the problem I'm facing right now is that when I do a query it doesn't do it, it skip the lines, for example:
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.countInBackground(new CountCallback() {
public void done(int count, ParseException e) { //skip all of thisthis
if (e == null) {
num=count;
} else {
//error
}
}
});
So, I'm not able to get the results, what I'm doing wrong?
Use
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
num = objects.size();
} else {
// Something went wrong.
}
}
});
There are many different types of query depends on what you want to. So if you're doing a query to get total number of users or objects in list. It can be done in the following manner.
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.countInBackground(new CountCallback() {
public void done(int count, ParseException e) {
if (e == null) {
// The count request succeeded. Log the count
num = count;
Log.d("Count", "Total number of users is " + num);
} else {
// The request failed
}
}
});

Retrieve data from a class in Parse.com

I have a class in Parse.com, as XYZ, and it has columns email, password, phone, age. I have email and password combination and I want to check whether there is such a combination in the class? How do I do this?
I have a class Donate, and I have been given an email(e) and password(pw). Here goes the code:
`ParseQuery<ParseObject> query = ParseQuery.getQuery("donate");
query.whereEqualTo("email", e);
query.whereEqualTo("password", pw);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(), "Success!!!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Something went wrong!!!", Toast.LENGTH_LONG).show();
}
}
}); `
And this always shows 'success' irrespective of the strings e, and pw.
ParseQuery return ParseException just if there was technical issue calling the server.
else, even though your query doesn't find exactly what you looked for,
it will return an empty list and the 'e' var will be null.
so what you need to do is :
ParseQuery<ParseObject> query = ParseQuery.getQuery("donate");
query.whereEqualTo("email", e);
query.whereEqualTo("password", pw);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
if (list.isEmpty() == false) { // add this
Toast.makeText(getApplicationContext(), "Success!!!", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Worng password!!!", Toast.LENGTH_LONG).show(); // add this
}
} else {
Toast.makeText(getApplicationContext(), "Something went wrong!!!", Toast.LENGTH_LONG).show();
}
}
});

Sort ParseQuery by boolean field

I want to sort my query first if a field is true or false, and then by updatedAt. How do I achieve this on Android with Parse SDK?
My current code is:
mQuery.orderByDescending("draft");
mQuery.addAscendingOrder("updatedAt");
But I get java.lang.IllegalArgumentException: Unable to sort by key draft.
First parse the query with draft values true with ascending order of updateTime and store the values to an array. After fetching this parse the query with draft values false.
ArrayList<ParseObject> result=new ArrayList();
ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
query.whereEqualTo("draft", true);
query.orderByAscending("updatedAt");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> object, ParseException e) {
if (object == null) {
Log.d("score", "The getFirst request failed.");
} else {
result=object;
ParseQuery<ParseObject> query1 = ParseQuery.getQuery("_User");
query1.whereEqualTo("draft", false);
query1.orderByAscending("updatedAt");
query1.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> object, ParseException e) {
if (object == null) {
Log.d("score", "The getFirst request failed.");
} else {
result=object;
for(int i=0;i<object.size();i++)
{
result.add(object.get(i));
}
}
}
});
}
}
});
Try using
mquery.whereEqualTo("True","draft");
instead of orderByDescending.

Query particular Parse user's information?

I have the objectID of a particular user (who is not the current user) and would like to find his Display Name, which is a custom field that I created.
As per Parse's guide, this code will create a list of users that match some particular attributes.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("gender", "female");
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
} else {
// Something went wrong.
}
}
});
There's no reason for me to make a list, however, if only one user has that objectID. Any way for me to just get the display name of a particular user?
What you want instead is getFirstInBackground(), e.g.:
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getFirstInBackground(someUserId, new GetCallback<ParseUser>() {
public void done(ParseUser user, ParseException e) {
if (e == null) {
// The query was successful.
// check if we got a match
if (user == null) {
// no matching user!
} else {
// great, get the name etc
}
} else {
// Something went wrong.
}
}
});

Categories

Resources