I am looking at the Parse documentation, and there is this interesting function I would like to use to make validate for signing up users if the username and email provided are registered (taken) or not. The documentation provides example for the following:
var lotsOfWins = PFQuery(className:"Player")
lotsOfWins.whereKey("wins", greaterThan:150)
var fewWins = PFQuery(className:"Player")
fewWins.whereKey("wins", lessThan:5)
var query = PFQuery.orQueryWithSubqueries([lotsOfWins, fewWins])
query.findObjectsInBackgroundWithBlock {
(results: [PFObject]?, error: NSError?) -> Void in
if error == nil {
// results contains players with lots of wins or only a few wins.
}
}
my version of it is:
/*Check username and email not taken*/
let usernameInputCheck = PFQuery(className:"_User")
usernameInputCheck.whereKey("appUsername", equalTo: self.usernameTxtField.text!)
let emailInputCheck = PFQuery(className:"_User")
emailInputCheck.whereKey("email", equalTo:self.emailTxtField.text!)
let query = PFQuery.orQueryWithSubqueries([usernameInputCheck, emailInputCheck])
query.findObjectsInBackgroundWithBlock {
(results: [PFObject]?, error: NSError?) -> Void in
if error == nil {
// results contains players with lots of wins or only a few wins.
}
}
I want to be able to check if email or username is taken, and if yes set a flag so that I can set message to user saying for example: "Email provided is already registered" or "Username is not available, try a different one".
Thanks for your help in advance.
Update: Here is the link to Parse docs: https://parse.com/docs/ios/guide#queries-compound-queries