mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Got rid of javascript-based random generator
This commit is contained in:
@@ -56,26 +56,11 @@ $(function () {
|
||||
|
||||
// Vouchers
|
||||
$("#voucher-bulk-codes-generate").click(function () {
|
||||
var charset = "ABCDEFGHKLMNPQRSTUVWXYZ23456789",
|
||||
i = 0, j = 0, len = parseInt($(this).attr("data-length")),
|
||||
num = parseInt($("#voucher-bulk-codes-num").val()), text = "";
|
||||
for (j = 0; j < num; j++) {
|
||||
var key = [];
|
||||
if (window.crypto && window.crypto.getRandomValues && Uint8Array) {
|
||||
key = new Uint8Array(len);
|
||||
window.crypto.getRandomValues(key);
|
||||
} else {
|
||||
for (i = 0; i < len; i++) {
|
||||
key.push(Math.floor(Math.random() * charset.length));
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
text += "\n";
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
text += charset.charAt(key[i] % charset.length);
|
||||
}
|
||||
}
|
||||
$("#id_codes").html(text);
|
||||
var url = $(this).attr("data-rng-url"),
|
||||
num = $("#voucher-bulk-codes-num").val();
|
||||
$("#id_codes").html("Generating...");
|
||||
$.getJSON(url + '?num=' + num, function (data) {
|
||||
$("#id_codes").text(data.codes.join("\n"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user