diff --git a/system/templates/account.create.html.twig b/system/templates/account.create.html.twig
index 245adc4e..cb89d4b3 100644
--- a/system/templates/account.create.html.twig
+++ b/system/templates/account.create.html.twig
@@ -34,6 +34,9 @@
Account {% if constant('USE_ACCOUNT_NAME') %}Name{% else %}Number{% endif %}:
+ {% if not constant('USE_ACCOUNT_NAME') %}
+
+ {% endif %}
|
@@ -336,3 +339,8 @@
{{ hook('HOOK_ACCOUNT_CREATE_AFTER_FORM') }}
+
diff --git a/system/templates/account.create.js.html.twig b/system/templates/account.create.js.html.twig
index 5dfb4b4b..74bfb8bf 100644
--- a/system/templates/account.create.js.html.twig
+++ b/system/templates/account.create.js.html.twig
@@ -20,6 +20,9 @@
$('#password2').blur(function() {
checkPassword();
});
+ $('#SuggestAccountNumber a').click(function (event) {
+ generateAccountNumber(event);
+ });
});
function updateFlag()
@@ -192,4 +195,18 @@
lastSend = timeNow;
}
+
+ function generateAccountNumber(event)
+ {
+ event.preventDefault();
+ $.getJSON("tools/generate_account_number.php", { uid: Math.random() },
+ function(data){
+ if(data.hasOwnProperty('success')) {
+ $('#account_input').val(data.success);
+ }
+ }
+ );
+
+ setTimeout(checkAccount, 1000);
+ }
diff --git a/tools/generate_account_number.php b/tools/generate_account_number.php
new file mode 100644
index 00000000..6529f485
--- /dev/null
+++ b/tools/generate_account_number.php
@@ -0,0 +1,54 @@
+
+ * @copyright 2021 MyAAC
+ * @link https://my-aac.org
+ */
+
+// we need some functions
+require '../common.php';
+require SYSTEM . 'functions.php';
+require SYSTEM . 'init.php';
+
+if(USE_ACCOUNT_NAME) {
+ return;
+}
+
+$hasNumberColumn = $db->hasColumn('accounts', 'number');
+do {
+ $length = 10;
+ $min = (int)(1 . str_repeat(0, $length - 1));
+ $max = (int)str_repeat(9, $length);
+
+ try {
+ $number = random_int($min, $max);
+ } catch (Exception $e) {
+ error_('');
+ }
+
+ $query = $db->query('SELECT `id` FROM `accounts` WHERE `' . ($hasNumberColumn ? 'number' : 'id') . '` = ' . $db->quote($number));
+} while($query->rowCount() >= 1);
+
+success_($number);
+
+/**
+ * Output message & exit.
+ *
+ * @param string $desc Description
+ */
+function success_($desc) {
+ echo json_encode([
+ 'success' => $desc
+ ]);
+ exit();
+}
+function error_($desc) {
+ echo json_encode([
+ 'error' => $desc
+ ]);
+ exit();
+}
|