Update setVerified to take an optional key argument
If specified, the existing local key must match the given one or we will not update the record. // FREEBIE
This commit is contained in:
parent
33b4d398d6
commit
c60919ca0e
1 changed files with 21 additions and 8 deletions
|
@ -503,23 +503,36 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setVerified: function(identifier, verifiedStatus) {
|
setVerified: function(identifier, verifiedStatus, publicKey) {
|
||||||
if (identifier === null || identifier === undefined) {
|
if (identifier === null || identifier === undefined) {
|
||||||
throw new Error("Tried to set verified for undefined/null key");
|
throw new Error("Tried to set verified for undefined/null key");
|
||||||
}
|
}
|
||||||
if (!validateVerifiedStatus(verifiedStatus)) {
|
if (!validateVerifiedStatus(verifiedStatus)) {
|
||||||
throw new Error("Invalid verified status");
|
throw new Error("Invalid verified status");
|
||||||
}
|
}
|
||||||
|
if (arguments.length > 2 && !(publicKey instanceof ArrayBuffer)) {
|
||||||
|
throw new Error("Invalid public key");
|
||||||
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityRecord = new IdentityRecord({id: identifier});
|
var identityRecord = new IdentityRecord({id: identifier});
|
||||||
identityRecord.fetch().always(function() {
|
identityRecord.fetch().then(function() {
|
||||||
identityRecord.save({
|
if (!publicKey || equalArrayBuffers(identityRecord.get('publicKey'), publicKey)) {
|
||||||
verified: verifiedStatus
|
identityRecord.set({ verified: verifiedStatus });
|
||||||
}).then(function() {
|
|
||||||
|
if (identityRecord.isValid()) {
|
||||||
|
identityRecord.save({
|
||||||
|
}).then(function() {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reject(identityRecord.validationError);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("No identity record for specified publicKey");
|
||||||
resolve();
|
resolve();
|
||||||
}, function() { // catch
|
}
|
||||||
reject(new Error("No identity record for " + identifier));
|
}, function() { // catch
|
||||||
});
|
reject(new Error("No identity record for " + identifier));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue