How do I check if a username is taken with parse.com Javascript SDK when ACL:Public read/write is disable in all users inside User's class?
Explanation: For security reasons all my users in class/table User have a private ACL (Access control list), or in other words the ACL for public read/write is disable, it means that authenticated users can read only their own information.
As you can imagine any query to Users will get empty to non logged In users so there is no way to check if a user is already taken by using Query on User Class
I manage to work around this by singUp a new user and then Parse will return a 400 error with some good information:
{code: 202, error: "username Test already taken"}
The problem with that approach is that I'm doing the validation on real time while the user is typing on the text area field:
HTML AngularJS:
<form name="form">
<h3>e-mail</h3>
<input class="form-control"
name="email"
placeholder="try john.doe@mail.com or bad@domain.com"
type="email"
required ng-model="email"
ng-model-options="{ debounce: 100 }"
ui-validate="{blacklist: 'notBlackListed($value)'}"
ui-validate-async="{alreadyExists: 'doesNotExist($modelValue)'}"
>
<span ng-show='form.email.$error.blacklist'>This e-mail is black-listed!</span>
<span ng-show='form.email.$error.alreadyExists'>This e-mail is <b>already taken!</b></span>
<span ng-show='form.email.$pending'>Verifying e-mail on server...</span>
<br>is form valid: {{form.$valid}}
</form>
Javascript AngularJS:
$scope.doesNotExist = function (value) {
Parse.initialize(KEY0, KEY1);
var deferral = $q.defer();
var user = new Parse.User();
user.set("username", "Test");
user.set("password", "anyapssword");
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
console.log("success!");
// Holly shit now I have to delete the user :( and wait for the full form to be submmited
user.destroy({
success: function(myObject) {
// The object was deleted from the Parse Cloud.
console.log("destroy!!!!!!!!!!!");
},
error: function(myObject, error) {
// The delete failed.
// error is a Parse.Error with an error code and message.
console.log("failed destroy!!!!!!!!!!!");
}
});
deferral.resolve(user);
},
error: function(user, error) {
console.log("Error: " + error.code + " " + error.message);
deferral.reject("mierda!");
}
});
return deferral.promise;
};
So how can I check if a username is taken with parse.com when ACL:Public read/write is disable?
I'm using the AngularUI plugIn to fast validation: https://htmlpreview.github.io/?https://github.com/angular-ui/ui-validate/master/demo/index.html
Thanks!