User accounts and the ACL
Behaviour
Without an ACL the instance has no users: every request is anonymous and the user routes return nothing. PRIVATE or PUBLIC names the ACL connection and its schema.table; PRIVATE also requires a login for every request. See the access control variables. The queries below use acl_schema.acl_table, replaced with the configured names. Passwords are stored encrypted and cannot be read back.
- Register (
/api/user/register): an email and a password matchingPASSWORD_REGEXP(default: upper and lower case letters, a digit, at least 12 characters).USER_DOMAINSrestricts the email domains. Registering an existing email stores the new password as a pending reset.[1] - Verify (
/api/user/verify?key=…): the emailed token, valid once, setsverified, resets failed attempts and applies a pending password. Admins are emailed to approve the account.[2] - Approve: an admin sets
approvedin the admin view. Login requires bothverifiedandapproved. - Log in (
/api/user/login): checks the password and sets the user cookie; see authentication.[3] - Failed logins: each wrong password increments
failedattemptsand emails the user. ReachingFAILED_ATTEMPTS(default 3) removes verification and emails a new verification token. - Blocked accounts cannot log in, register or reset their password. Cookies and tokens issued before the block stay valid until they expire; see revocation.
- Expiry: with
APPROVAL_EXPIRYdays, an account's approval lapses atexpires_on, set at registration. - A
nullpassword restricts an account to SAML or a custom provider.
Flow
login.js → fromACL.js (lookup, password check, failed attempts, session) → redirect.js (cookie, redirect). register.js and verify.js write the ACL and send mail templates through the mailer.
Where to change
- Account rules:
apps/xyz/mod/user/fromACL.jsandregister.js. - Mail and page texts: the language templates of
mod/workspace/templates. - Admin listing and updates:
list.js,update.js,admin.js.
Tests
apps/xyz/tests/mod/user/ covers registration, login, verification and the ACL queries with a mocked ACL.
Pitfalls
- The ACL table needs a
sessioncolumn whenUSER_SESSIONis set. - Registration has no throttle of its own; rate limiting is instance wide (
RATE_LIMIT). - The
processEnvJSDoc gives a 10 character password default; the register module requires 12.
ACL table
sql
CREATE TABLE acl_schema.acl_table (
"_id" serial not null,
email text not null,
password text,
verified boolean default false,
approved boolean default false,
verificationtoken text,
approvaltoken text,
failedattempts integer default 0,
password_reset text,
api text,
approved_by text,
access_log text[] default '{}'::text[],
blocked boolean default false,
roles text[] default '{}'::text[],
admin boolean default false,
language text default 'en',
expires_on bigint,
session text
);