Skip to content

Commit

Permalink
Claim address page security improvements
Browse files Browse the repository at this point in the history
-Removed the ability to claim an address that has 0 transactions
-The "Claim" button is now disabled after submitting to help prevent double submissions
  • Loading branch information
joeuhren committed Mar 21, 2024
1 parent cf9dce3 commit 9c57b4b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
65 changes: 36 additions & 29 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,35 +460,42 @@ module.exports = {
},

update_claim_name: function(hash, claim_name, cb) {
// check if the claim name is being removed
if (claim_name == null || claim_name == '') {
// remove the claim name
ClaimAddress.findOneAndDelete({a_id: hash}).then(() => {
// run processes after the claim name has been updated
after_update_claim_name(hash, claim_name, function() {
return cb('');
});
}).catch((err) => {
console.log(err);
return cb(err);
});
} else {
// add or update the claim name
ClaimAddress.updateOne({a_id: hash}, {
a_id: hash,
claim_name: claim_name
}, {
upsert: true
}).then(() => {
// run processes after the claim name has been updated
after_update_claim_name(hash, claim_name, function() {
return cb('');
});
}).catch((err) => {
console.log(err);
return cb(err);
});
}
// check if the address has received coins before by looking up the address in the local database
module.exports.get_address(hash, false, function(address) {
// check if the address was found in the local database
if (address) {
// check if the claim name is being removed
if (claim_name == null || claim_name == '') {
// remove the claim name
ClaimAddress.findOneAndDelete({a_id: hash}).then(() => {
// run processes after the claim name has been updated
after_update_claim_name(hash, claim_name, function() {
return cb('');
});
}).catch((err) => {
console.log(err);
return cb(err);
});
} else {
// add or update the claim name
ClaimAddress.updateOne({a_id: hash}, {
a_id: hash,
claim_name: claim_name
}, {
upsert: true
}).then(() => {
// run processes after the claim name has been updated
after_update_claim_name(hash, claim_name, function() {
return cb('');
});
}).catch((err) => {
console.log(err);
return cb(err);
});
}
} else
return cb('no_address');
});
},

update_richlist_claim_name: function(hash, claim_name, cb) {
Expand Down
6 changes: 6 additions & 0 deletions views/claim_address.pug
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ block content
) {
showClaimAlert('warning', 'The captcha validation has not been set', false);
} else {
$('button.btn-success').attr('disabled', true);

if ('#{selected_captcha_name}' == 'google_recaptcha2' && '#{settings.captcha.google_recaptcha2.captcha_type}' == 'invisible') {
grecaptcha.execute();
} else if ('#{selected_captcha_name}' == 'google_recaptcha3') {
Expand Down Expand Up @@ -117,13 +119,17 @@ block content
// clear out the captcha to allow the form to be submitted again
grecaptcha.reset();
}

$('button.btn-success').attr('disabled', false);
});
}
function onSubmit(token) {
submitForm(token);

// ensure the onSubmit event can fire again without needing to reload the page in the event that the server returns an error and the form must be submitted again
grecaptcha.reset();

$('button.btn-success').attr('disabled', false);
}
.col-xs-12.col-md-12
if settings.claim_address_page.page_header.show_img == true || settings.claim_address_page.page_header.show_title == true || settings.claim_address_page.page_header.show_description == true
Expand Down

0 comments on commit 9c57b4b

Please sign in to comment.