0cb315ea88
CI / build (push) Has been cancelled
Event photos can now be opened in Lumenroom, a WebGL2 develop module, from the photo editor's Advanced button. The dashboard signs a short-lived token scoped to one user and event; Lumenroom exchanges it, imports the event's photo list and proxies bytes on demand, so nothing is copied and the temporary catalog expires with the bridge session. Saving in Lumenroom renders the photo and writes it back as the event's edited JPEG, with the advanced recipe kept in event_photos.advanced_edit_json. Lumenroom is vendored under lumenroom/ and built as a second compose service, so one clone and `docker compose up -d --build` deploys both apps. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import crypto from 'node:crypto';
|
|
import { SESSION_DAYS } from './config.mjs';
|
|
import { sessions, users } from './db.mjs';
|
|
|
|
const KEYLEN = 64;
|
|
|
|
export function hashPassword(password) {
|
|
const salt = crypto.randomBytes(16);
|
|
const hash = crypto.scryptSync(password, salt, KEYLEN);
|
|
return `scrypt$${salt.toString('hex')}$${hash.toString('hex')}`;
|
|
}
|
|
|
|
export function verifyPassword(password, stored) {
|
|
const [scheme, saltHex, hashHex] = String(stored).split('$');
|
|
if (scheme !== 'scrypt' || !saltHex || !hashHex) return false;
|
|
const expected = Buffer.from(hashHex, 'hex');
|
|
const actual = crypto.scryptSync(password, Buffer.from(saltHex, 'hex'), expected.length);
|
|
return expected.length === actual.length && crypto.timingSafeEqual(expected, actual);
|
|
}
|
|
|
|
export function createSession(userId) {
|
|
const token = crypto.randomBytes(32).toString('hex');
|
|
const expiresAt = Date.now() + SESSION_DAYS * 24 * 60 * 60 * 1000;
|
|
sessions.purge();
|
|
sessions.create(token, userId, expiresAt);
|
|
return token;
|
|
}
|
|
|
|
export function publicUser(row) {
|
|
if (!row) return null;
|
|
return {
|
|
id: row.id,
|
|
email: row.email,
|
|
name: row.name ?? '',
|
|
role: row.role ?? 'member',
|
|
};
|
|
}
|
|
|
|
export function authenticate(req) {
|
|
const header = String(req.headers.authorization ?? '');
|
|
const token = header.startsWith('Bearer ') ? header.slice(7).trim() : '';
|
|
if (!token) return null;
|
|
const session = sessions.find(token);
|
|
if (!session) return null;
|
|
if (Number(session.expires_at) < Date.now()) {
|
|
sessions.destroy(token);
|
|
return null;
|
|
}
|
|
return publicUser(users.byId(session.user_id));
|
|
}
|
|
|
|
export function normalizeEmail(value) {
|
|
return typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
}
|
|
|
|
export function validEmail(email) {
|
|
return /^[^@\s]+@[^@\s]+\.[^@\s]{2,}$/.test(email);
|
|
}
|