Spreadsheet-UX op een echte relationele engine

main

Deze repository wordt als momentopname gepubliceerd: een clone bevat de volledige inhoud, maar geen commitgeschiedenis.

2.1 kB Ruw bestand
import { config } from '../config.js';
import { getAccountByEmail } from '../control/accounts.js';
import { issueToken } from '../control/tokens.js';
import { publicLink } from '../mail/mailer.js';
import { openInstallation } from './install.js';

/**
 * Issue a password-reset link from the command line.
 *
 * The operator's way back in, and the only one that works on an install with
 * no email configured. It is deliberately not a route: a workspace admin
 * cannot do this to a member, because the account is not theirs — the same
 * person may be running someone else's workspace next door. Whoever can reach
 * the server can already read every database on it, so nothing new is granted
 * by letting them reach an account.
 *
 *   npm run recover -- --email someone@example.com
 */
function flag(name: string): string | undefined {
  const index = process.argv.indexOf(`--${name}`);
  if (index === -1) return undefined;
  return process.argv[index + 1];
}

const email = flag('email');
if (!email) {
  console.error('Usage: npm run recover -- --email someone@example.com');
  process.exit(2);
}

const install = openInstallation();

try {
  const account = getAccountByEmail(install.control, email);
  if (!account) {
    console.error(`[wellformed] no account for ${email} in ${config.controlDbPath}`);
    process.exit(1);
  }
  if (account.disabled) {
    console.error(`[wellformed] the account for ${email} is disabled; a reset link would not work.`);
    process.exit(1);
  }

  const { token, record } = issueToken(install.control, account.id, 'reset');

  console.log('');
  console.log(`  Reset link for ${account.name} <${account.email}>:`);
  console.log('');
  console.log(`    ${publicLink(`/reset/${token}`)}`);
  console.log('');
  console.log(`  Works once, expires ${record.expiresAt.replace('T', ' ').slice(0, 19)} UTC.`);
  console.log('  Any reset link issued earlier for this account has just stopped working.');
  console.log('');
  console.log(`  Set WELLFORMED_PUBLIC_URL if ${config.publicUrl} is not where people reach this install.`);
  console.log('');
} finally {
  install.close();
}