Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(js/captcha): add new random string to load captcha image
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 20, 2019
1 parent a3eb839 commit 91a2e33
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apps/public/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ function humanFileSize(bytes, fix, si) {
return bytes.toFixed(fix ? fix : 2) + ' ' + units[u];
}

function randomString(length = 16, charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
let result = '';
let charactersLength = charset.length;
for (let i = 0; i < length; i++) {
result += charset.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}

function location_search_replace(new_params) {
let search = _location_search;
for (let i in new_params) {
Expand Down Expand Up @@ -74,7 +83,7 @@ jQuery(document).ready(function () {
// Captcha Img Re-flush
let captcha_img_another = $('.captcha_img');
captcha_img_another.on('click', function () {
$(this).attr('src', '/captcha?t=' + Date.now()) // Change src to get another captcha image
$(this).attr('src', `/captcha?t=${Date.now()}&r=${randomString(6)}`) // Change src to get another captcha image
.parent('.captcha_img_load').addClass('load-indicator loading'); // Add loading indicator in parent of img tag
});
captcha_img_another.on('load', function () {
Expand Down

0 comments on commit 91a2e33

Please sign in to comment.