mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(admin): a temporary password for a player who lost access
The account view's Lost access box gives the account a new random password (12 characters, none that look alike), shown once with a Copy button. It signs them out everywhere and forgets trusted devices; "Turn off their 2FA too" is for a lost authenticator. Written to the mod log, without the password. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a860a67626
commit
0f367c55b8
2 files changed
+53
-1
No files matched your search
@@ -383,6 +383,13 @@ const gift = (account, body) => {
|
||||
|
||||
const MAX_QUEST_LEVEL = 100;
|
||||
|
||||
// a password for a player who lost theirs: read out or pasted to them, so
|
||||
// nothing that looks like something else (0 O, 1 l I).
|
||||
const TEMP_PASSWORD_LETTERS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
|
||||
const TEMP_PASSWORD_LENGTH = 12;
|
||||
const randomPassword = () => Array.from({length: TEMP_PASSWORD_LENGTH},
|
||||
() => TEMP_PASSWORD_LETTERS[crypto.randomInt(TEMP_PASSWORD_LETTERS.length)]).join("");
|
||||
|
||||
const wholeNumber = (value, min, max) => (Number.isInteger(value) && value >= min && value <= max ? value : null);
|
||||
|
||||
// returns {ok: text} or {error: text}.
|
||||
@@ -537,6 +544,27 @@ const act = (account, body) => {
|
||||
}
|
||||
// guide: lets the player log in as one (lib/accounts.js setLoginChoices).
|
||||
// it shows from their next login.
|
||||
// lost access: a new random password, shown here once. it signs them out
|
||||
// everywhere (lib/accounts.js setPassword); with `twoStepOff` their 2FA
|
||||
// goes as well, for a lost authenticator.
|
||||
case "tempPassword": {
|
||||
let password = randomPassword();
|
||||
// the account rules want a capital, a small letter and a digit, and no
|
||||
// common word or the username in it: draw again until it has them.
|
||||
while (accounts.setPassword(account, password)) {
|
||||
password = randomPassword();
|
||||
}
|
||||
const twoStepOff = body.twoStepOff === true && totp.isOn(account);
|
||||
if (twoStepOff) {
|
||||
totp.turnOff(account);
|
||||
}
|
||||
accounts.save(account);
|
||||
world.disconnect(account);
|
||||
manage.forget(account);
|
||||
modpanel.forget(account);
|
||||
modlog.record("admin", "temporary password set", account.username, twoStepOff ? "2FA turned off" : "");
|
||||
return {ok: `${name}'s password is now ${password}${twoStepOff ? " and their 2FA is off" : ""}. Ask them to change it on their account page.`, password};
|
||||
}
|
||||
case "guide": {
|
||||
const on = body.on === true;
|
||||
account.guideGiven = on;
|
||||
|
||||
+25
-1
@@ -502,6 +502,15 @@
|
||||
<div class="row"><input id="new-name" maxlength="100" placeholder="New username" autocomplete="off" spellcheck="false" aria-label="New username">
|
||||
<button type="button" data-action="rename">Rename</button></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<h3>Lost access</h3>
|
||||
<p class="hint">A new random password, shown once. They are signed out everywhere and should change it on their account page.</p>
|
||||
<div class="row"><label class="check"><input type="checkbox" id="temp-two-step-off"> Turn off their 2FA too</label></div>
|
||||
<div class="row" style="margin-top:8px"><button type="button" data-action="tempPassword">Make temporary password</button></div>
|
||||
<div class="row" style="margin-top:8px" id="temp-password-row" hidden>
|
||||
<input id="temp-password" readonly aria-label="Temporary password" spellcheck="false" style="font-family:monospace">
|
||||
<button type="button" id="temp-password-copy">Copy</button></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<h3>Adventure level</h3>
|
||||
<div class="row"><input id="quest-level" type="number" min="0" max="100" step="1" aria-label="Adventure level of the animal in use">
|
||||
@@ -1529,6 +1538,7 @@
|
||||
label.append(box, ` ${badge.label}`);
|
||||
return label;
|
||||
}));
|
||||
$("temp-two-step-off").disabled = !current || !current.twoStep;
|
||||
$("guide-toggle").textContent = current && current.guide ? "Remove guide" : "Make guide";
|
||||
$("discord-name").textContent = current && current.discord ? `Discord: ${current.discord}` : "No Discord linked";
|
||||
$("admin-dashboard-access").textContent = current && current.adminDashboardAccess ? "Remove Discord dashboard access" : "Allow Discord dashboard access";
|
||||
@@ -1566,7 +1576,8 @@
|
||||
selected = username;
|
||||
current = null;
|
||||
setStatus($("detail-status"), "");
|
||||
for (const id of ["new-name", "ban-hours", "silence-hours", "message-text", "gems-amount", "gift-value", "gift-text"]) {
|
||||
$("temp-password-row").hidden = true;
|
||||
for (const id of ["temp-password", "new-name", "ban-hours", "silence-hours", "message-text", "gems-amount", "gift-value", "gift-text"]) {
|
||||
$(id).value = "";
|
||||
}
|
||||
hashArg = username;
|
||||
@@ -1720,6 +1731,7 @@
|
||||
case "permissions": return permissionChoices();
|
||||
case "adminDashboardAccess": return {on: !(current || {}).adminDashboardAccess};
|
||||
case "guide": return {on: !(current || {}).guide};
|
||||
case "tempPassword": return {twoStepOff: $("temp-two-step-off").checked};
|
||||
case "message": return {text: $("message-text").value};
|
||||
case "gems": return {amount: numberFrom("gems-amount")};
|
||||
case "gift": return giftBody();
|
||||
@@ -1731,6 +1743,10 @@
|
||||
}
|
||||
};
|
||||
|
||||
$("temp-password-copy").addEventListener("click", () => {
|
||||
navigator.clipboard.writeText($("temp-password").value).catch(() => $("temp-password").select());
|
||||
});
|
||||
|
||||
// the "N ago" buttons fill the last-seen box and press Set.
|
||||
$("detail").addEventListener("click", event => {
|
||||
const quick = event.target.closest("button[data-ago]");
|
||||
@@ -1760,6 +1776,9 @@
|
||||
if (action === "banDevices" && !window.confirm(`Hardware ban ${selected}? Everyone on their hardware is put out.`)) {
|
||||
return;
|
||||
}
|
||||
if (action === "tempPassword" && !window.confirm(`Give ${selected} a new random password? Their old one stops working and they are signed out everywhere.`)) {
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
const result = await api("account", {username: selected, action, ...actionBody(action)});
|
||||
button.disabled = false;
|
||||
@@ -1767,6 +1786,11 @@
|
||||
if (result.ok && action === "delete") {
|
||||
selected = null;
|
||||
}
|
||||
if (result.ok && action === "tempPassword") {
|
||||
$("temp-password").value = result.data.password;
|
||||
$("temp-password-row").hidden = false;
|
||||
$("temp-two-step-off").checked = false;
|
||||
}
|
||||
if (result.ok && action === "rename") {
|
||||
selected = result.data.username;
|
||||
$("new-name").value = "";
|
||||
|
||||
Reference in new issue
Block a user