diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ffcdc624..db157aa2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -214,6 +214,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tabs that don't fit across the screen go into More at the end of the row, instead of running off the edge out of sight or wrapping onto more lines - a list's views (the tickets list at most screen sizes), a record page's tabs (a contact's, an asset's, a location's), a quick look's, a form's, and the kinds in Admin > Categories and Tags on a phone. The tab you're on always stays out, and More shows a red or amber count when a tab in it needs attention, such as Overdue, Unassigned or a contact's open tickets. - Linking: Link - along the top of a record's page, on its tabs and in quick looks - opens a list right under it instead of a window. What's linked already is ticked: tick to link, untick to unlink, and it's saved when you click Done or anywhere else, with one message for what changed. It covers documents, files, assets, contacts, licenses, credentials, vendors, services, locations, domains and certificates, a contact's assets and credentials and an asset's credentials, a project's and a service's tickets, a ticket's services and its related tickets. A document's or file's Link lists every kind it can be linked to, in groups. Tickets are no longer added to a project by typing their numbers - tick them in the list (open ones and those closed in the last 90 days), or change the project on the ticket. +- Sign-in codes: the 6-digit code - signing in with two-step sign-in, setting it up (yours, or a contact's in the client portal), and the code emailed for a shared link - goes in six boxes, three and three. Paste or let your phone or password manager fill it, "123 456" too, and it goes as soon as the sixth digit is in - no need to click the button. A wrong code turns the boxes red. On the sign-in page Remember this browser now comes before the code, so tick it first. + ### Bug Fixes - Invoices, quotes and recurring invoices: leaving the page in the middle of typing a note asked "Leave page?" - even though the note saves as you go. It now saves on the way out instead. @@ -421,6 +423,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Starter content: `starterPackRecords()`, `starterPackHere()`, `starterPackUsed()`, `starterContentUnused()` and `starterClearUnused()` in `admin/post/starter_content_model.php`, `clear_starter_unused` in `admin/post/starter_content.php` (rechecked on post, with an Undo of the archive) and `admin/modals/starter_content/starter_clear.php`. A tag counts as used by any table with a `tag_id` or `*_tag_id` column (read from information_schema) or a seat count, a project template by its tickets' history line, and a category by `categoryUsage()` plus ticket templates, settings, RMM alerts, AI triage and child categories. `starterPickHtml()` takes `$open`; `js/starter_content.js` counts `data-starter-format="clear"` and sets up a pack in a window as it opens. - Tab rows: `js/tab_fold.js` (loaded by `includes/footer.php`) folds the tabs that don't fit into a More dropdown, from the end, never the `.active` one - in `.nav.itflow-asset-tabs` (or a `.nav` inside an `.itflow-asset-tabs` card header), `.nav.itflow-asset-pills`, `.nav.itflow-asset-form-tabs` and any `.nav.itflow-tabs-foldable` (added to the kinds in Admin > Categories and Tags and to the mail settings tabs). A tab is a `.nav-link` of the row or the `.nav-item` around one; rows in a window are set up on `shown.bs.modal`, and a row laid out as a column, or not on screen yet, is left as it is. Folded tabs stay in place with `.itflow-tab-folded`, so Bootstrap's tabs and page scripts keep working on them; More is a `.nav-link.dropdown-toggle` (left out by Bootstrap's tabs and by `agent/js/tickets_live.js`), and its items are built on `show.bs.dropdown` - a link for a tab with an href, otherwise a button that clicks the tab. The row gets `.itflow-tabs-fold` (one line, overflow visible, min-width 0, its tabs `nowrap`), and fits again on resize, font load and any change to its tabs (a MutationObserver - counts updated in place, the open tab changing). - Link picker: `functions/link_picker.php` (`linkPickerButton()`, `linkPickerSource()`, `linkPickerOptions()`, `linkPickerSave()`, `LINK_PICKER_OWN` for the links that aren't `LINK_RELATIONS` pairs), `js/link_picker.js`, and `agent/ajax.php` `link_picker` (GET: the options, linked ones selected) and `link_picker_save` (POST `add[]` and `remove[]`; `flash=1` keeps the message for the page it reloads). It opens the select picker on a hidden multiple ` - + true]) ?> diff --git a/agent/user/mfa_enforcement.php b/agent/user/mfa_enforcement.php index 5071e6a0f..d39d93dd6 100644 --- a/agent/user/mfa_enforcement.php +++ b/agent/user/mfa_enforcement.php @@ -90,6 +90,7 @@ $mfa_secret = $_SESSION['mfa_token']; + + diff --git a/client/profile.php b/client/profile.php index 48c322b8d..318491882 100644 --- a/client/profile.php +++ b/client/profile.php @@ -307,10 +307,7 @@ $csrf = escapeHtml($_SESSION['csrf_token']);
  1. Enter the 6-digit code it shows:
-
- - -
+ 'mb-3', 'submit' => true, 'autofocus' => true]) ?>
diff --git a/css/itflow_custom.css b/css/itflow_custom.css index 9415fdcd9..612322e37 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -6628,12 +6628,99 @@ tr:hover .itflow-files-rename, width: 12rem; height: 12rem; } -.itflow-mfa-code { - letter-spacing: .4em; + +/* A 6-digit code in six boxes (otpCodeInput(), js/otp_input.js). The one real field lies + over the boxes, see-through, so typing, pasting and autofill all go to it; the boxes only + show its digits. Before the script runs it is a plain field. */ +.itflow-otp.is-ready { + position: relative; + display: flex; + justify-content: center; + gap: .5rem; + width: 100%; + max-width: 22rem; + margin-inline: auto; } -.itflow-mfa-code::placeholder { - letter-spacing: .4em; - opacity: .35; +.itflow-otp.is-ready > .itflow-otp-input { + position: absolute; + inset: 0; + z-index: 1; + width: 100%; + height: 100%; + padding: 0; + font-size: 16px; + color: transparent; + -webkit-text-fill-color: transparent; + caret-color: transparent; + background: transparent; + border: 0; + box-shadow: none; + outline: 0; + cursor: text; +} +.itflow-otp.is-ready > .itflow-otp-input::selection { + background: transparent; +} +.itflow-otp.is-ready > .itflow-otp-input::placeholder { + color: transparent; +} +/* Autofilled - keep the browser's colour off */ +.itflow-otp.is-ready > .itflow-otp-input:-webkit-autofill { + transition: background-color 600000s 0s, color 600000s 0s; +} +.itflow-otp-slot { + display: flex; + flex: 1 1 0; + align-items: center; + justify-content: center; + min-width: 0; + max-width: 3rem; + height: 3.5rem; + font-family: var(--bs-font-monospace); + font-size: 1.6rem; + font-weight: 600; + color: var(--bs-body-color); + background: var(--bs-body-bg); + border: 1px solid var(--bs-border-color); + border-radius: var(--bs-border-radius-lg); + transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out; +} +.itflow-otp-slot.is-filled { + border-color: var(--bs-secondary-color); +} +.itflow-otp-slot.is-active { + border-color: rgba(var(--bs-primary-rgb), .75); + box-shadow: 0 0 0 .2rem rgba(var(--bs-primary-rgb), .25); +} +/* The next digit goes here - a blinking caret */ +.itflow-otp-slot.is-caret::after { + content: ""; + width: 2px; + height: 1.6rem; + background: var(--bs-body-color); + animation: itflow-otp-caret 1s step-end infinite; +} +@keyframes itflow-otp-caret { + 50% { opacity: 0; } +} +/* Three and three, as the codes are read out */ +.itflow-otp-sep { + flex: 0 0 .6rem; + align-self: center; + height: 2px; + background: var(--bs-border-color); + border-radius: 1px; +} +.itflow-otp.is-invalid .itflow-otp-slot { + border-color: var(--bs-form-invalid-border-color); +} +.itflow-otp.is-invalid .itflow-otp-slot.is-active { + box-shadow: 0 0 0 .2rem rgba(var(--bs-danger-rgb), .25); +} +@media (prefers-reduced-motion: reduce) { + .itflow-otp-slot.is-caret::after { + animation: none; + } } .itflow-mfa-state { display: inline-flex; diff --git a/functions/user.php b/functions/user.php index cefdadab5..63e673989 100644 --- a/functions/user.php +++ b/functions/user.php @@ -519,6 +519,38 @@ function userMfaQrSvg($secret, $email) { return qrCodeSvg($uri, 'class="itflow-mfa-qr" role="img" aria-label="QR code for your authenticator app"'); } +/** + * A 6-digit code, typed into six boxes - signing in with MFA, setting it up, + * and share codes. The one field under the boxes is what the form sends and + * what phones and password managers fill in; js/otp_input.js draws the boxes + * over it (a plain field without it). $options: id, label (its accessible + * name), class (on the wrapper), autofocus, submit (send the form once the + * sixth digit is in), invalid (a code that was just wrong - the boxes go red). + */ +function otpCodeInput($name, array $options = []) { + $attrs = [ + 'type' => 'text', + 'class' => 'form-control form-control-lg font-monospace text-center itflow-otp-input' . (empty($options['invalid']) ? '' : ' is-invalid'), + 'name' => $name, + 'id' => $options['id'] ?? '', + 'inputmode' => 'numeric', + 'pattern' => '[0-9]{6}', + 'minlength' => '6', + 'maxlength' => '6', + 'autocomplete' => 'one-time-code', + 'placeholder' => '000000', + 'aria-label' => $options['label'] ?? '6-digit code', + ]; + $html = ' $value) { + if ($value !== '') { + $html .= ' ' . $attr . '="' . escapeHtml($value) . '"'; + } + } + $html .= ' required data-otp' . (empty($options['submit']) ? '' : ' data-otp-submit') . (empty($options['autofocus']) ? '' : ' autofocus') . '>'; + return '
' . $html . '
'; +} + /** An agent's work not finished - [tickets not closed, recurring tickets] assigned to them. */ function userOpenWork($user_id) { global $mysqli; diff --git a/guest/share.php b/guest/share.php index 9e3baa388..a77a621f0 100644 --- a/guest/share.php +++ b/guest/share.php @@ -91,11 +91,7 @@ $item_id = intval($_GET['id'] ?? 0); @@ -255,6 +251,7 @@ $item_id = intval($_GET['id'] ?? 0);
+ "> + diff --git a/js/guest_share.js b/js/guest_share.js index 119e23def..8ca5d373b 100644 --- a/js/guest_share.js +++ b/js/guest_share.js @@ -214,6 +214,7 @@ gone(data.reason); } else if (data.error) { error('code', data.error); + form.code.classList.add('is-invalid'); form.code.select(); } else { form.code.value = ''; diff --git a/js/otp_input.js b/js/otp_input.js new file mode 100644 index 000000000..daa1781bd --- /dev/null +++ b/js/otp_input.js @@ -0,0 +1,158 @@ +/* + * A 6-digit code in six boxes - signing in with MFA, setting it up, and share + * codes (otpCodeInput() in functions/user.php draws the field). + * + * The one real field stays, see-through, over the boxes: it is what the form + * sends, what phones and password managers fill in, and what a screen reader + * reads. The boxes only show its digits, with the next one to type marked. + * Typing always adds at the end and Backspace takes the last one off; a pasted + * code ("123 456" too) fills them all. With data-otp-submit the form is sent + * once the sixth digit is in, as if its first button were pressed. + * + * Fields on the page are done on load; window.itflowOtp(input) does one added + * later. Setting the field's value from script redraws the boxes, and the + * is-invalid class on it turns them red until the next digit. + */ +(function () { + 'use strict'; + + const native = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value'); + + function init(input) { + if (!input || input.dataset.otpReady) { + return; + } + input.dataset.otpReady = '1'; + + const length = Number(input.getAttribute('maxlength')) || 6; + const wrap = input.parentNode; + const boxes = []; + for (let i = 0; i < length; i++) { + if (length === 6 && i === 3) { + const sep = document.createElement('span'); + sep.className = 'itflow-otp-sep'; + sep.setAttribute('aria-hidden', 'true'); + wrap.append(sep); + } + const box = document.createElement('span'); + box.className = 'itflow-otp-slot'; + box.setAttribute('aria-hidden', 'true'); + wrap.append(box); + boxes.push(box); + } + wrap.classList.add('is-ready'); + + let sent = ''; + + function digits(text) { + return String(text).replace(/\D/g, '').slice(0, length); + } + + function value() { + return native.get.call(input); + } + + // All of it selected - typing replaces the code + function allSelected() { + const n = value().length; + return n > 0 && input.selectionStart === 0 && input.selectionEnd === n; + } + + function render() { + const text = value(); + const focused = document.activeElement === input; + const all = focused && allSelected(); + const at = Math.min(text.length, length - 1); + boxes.forEach(function (box, i) { + box.textContent = text.charAt(i); + box.classList.toggle('is-filled', i < text.length); + box.classList.toggle('is-active', focused && (all || i === at)); + box.classList.toggle('is-caret', focused && !all && i === text.length); + }); + wrap.classList.toggle('is-invalid', input.classList.contains('is-invalid')); + } + + // The caret stays at the end, unless it's all selected + function toEnd() { + const n = value().length; + if (document.activeElement === input && !allSelected() && (input.selectionStart !== n || input.selectionEnd !== n)) { + input.setSelectionRange(n, n); + } + render(); + } + + function submit() { + const form = input.form; + const text = value(); + if (!('otpSubmit' in input.dataset) || !form || text.length !== length || text === sent || !form.checkValidity()) { + return; + } + sent = text; + const button = form.querySelector('button[type=submit], input[type=submit]'); + if (form.requestSubmit) { + form.requestSubmit(button || undefined); + } else if (button) { + button.click(); + } else { + form.submit(); + } + } + + // A value set from script redraws the boxes + Object.defineProperty(input, 'value', { + configurable: true, + get: value, + set: function (text) { + native.set.call(input, text); + if (value().length < length) { + sent = ''; + } + render(); + } + }); + + input.addEventListener('input', function () { + const clean = digits(value()); + if (clean !== value()) { + native.set.call(input, clean); + } + if (clean.length < length) { + sent = ''; + } + input.classList.remove('is-invalid'); + toEnd(); + submit(); + }); + + input.addEventListener('paste', function (e) { + const pasted = digits((e.clipboardData || window.clipboardData).getData('text')); + e.preventDefault(); + if (!pasted) { + return; + } + native.set.call(input, pasted.length >= length || allSelected() ? pasted : digits(value() + pasted)); + input.dispatchEvent(new Event('input', { bubbles: true })); + }); + + ['focus', 'click', 'keyup', 'select'].forEach(function (type) { + input.addEventListener(type, toEnd); + }); + input.addEventListener('blur', render); + + new MutationObserver(render).observe(input, { attributes: true, attributeFilter: ['class'] }); + + render(); + } + + window.itflowOtp = init; + + function initAll() { + document.querySelectorAll('input[data-otp]').forEach(init); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', initAll); + } else { + initAll(); + } +})(); diff --git a/login.php b/login.php index 7a57904cc..b3b6972c6 100644 --- a/login.php +++ b/login.php @@ -584,15 +584,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_ // Now that we've transferred what we need, it's safe to clear the dual-role pending session. unset($_SESSION['pending_dual_login']); - $token_field = " -
- -
- -
-
"; + $token_field = otpCodeInput('current_code', ['class' => 'mb-3', 'submit' => true, 'autofocus' => true, 'invalid' => $code_given && !$mfa_locked]); if ($mfa_locked) { @@ -700,14 +692,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_ ]; unset($_SESSION['pending_dual_login']); - $token_field = " -

Enter the 6-digit code from your authenticator app.

-
- - -
"; + $token_field = otpCodeInput('current_code', ['class' => 'mb-3', 'submit' => true, 'autofocus' => true, 'invalid' => !$client_mfa_locked && ($client_code !== '' || isset($_POST['current_code']))]); if ($client_mfa_locked) { // As for agents: no log row while locked, so the window can run out @@ -899,19 +884,21 @@ $show_login_form = (!$show_role_choice && !$show_mfa_form); - - + +

Enter the 6-digit code from your authenticator app.

- - -
+
+ + + + @@ -957,6 +944,7 @@ if (!$config_whitelabel_enabled) { +