当 ACL:公共读/写在用户类中的所有用户中被禁用时,如何检查 parse.com Javascript SDK 是否使用了用户名?
说明:出于安全原因,我在类/表用户中的所有用户都有一个私有ACL(访问控制列表),或者换句话说,公共读/写的 ACL 被禁用,这意味着经过身份验证的用户只能读取自己的信息。
正如您可以想象的那样,对用户的任何查询对于未登录的用户来说都是空的,因此无法通过对用户类使用查询来检查用户是否已经被占用
我设法通过 singUp 一个新用户来解决这个问题,然后 Parse 将返回一个 400 错误并提供一些有用的信息:
{code: 202, error: "username Test already taken"}
这种方法的问题在于,当用户在文本区域字段上键入时,我正在实时进行验证:
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;
};
那么,当 ACL:Public 读/写被禁用时,如何检查用户名是否与 parse.com 一起使用?
我正在使用 AngularUI 插件进行快速验证:https ://htmlpreview.github.io/?https://github.com/angular-ui/ui-validate/master/demo/index.html
谢谢!