Add password resets, change password, sign-out, a Branches link and moving staff

Gaps found while writing the user manual:

- Forgotten passwords: owners and managers can create a one-time
  password reset link from Staff (managers for their own cashiers). It
  expires after 24 hours; the old password works until it is used, and
  using it signs the account out everywhere. Reset and invite links share
  the invite page, which now says which it is. An owner who forgets their
  password gets a link from the platform operator (Platform console,
  "Owner password link"). The login page's "Forgot password?" explains
  this.
- Change password: any signed-in user, from the dashboard, the till or
  the platform console. Needs the current password; other devices are
  signed out.
- Sign out on the dashboard and the platform console (the till already
  had it), through one shared helper that also clears the till's cached
  session.
- A Branches link on the owner's dashboard; the page was only reachable
  by typing its address.
- Owners can move a manager or cashier to another branch from Staff. A
  moved manager stops being the old branch's manager and becomes the new
  branch's if it has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 13:57:04 +03:00
parent 418ad36b02
commit 6f8a5fe969
18 changed files with 582 additions and 47 deletions
+8 -3
View File
@@ -25,11 +25,15 @@ export interface IUser extends Document {
isActive: boolean;
failedLoginAttempts: number;
lockedUntil: Date | null;
// Pending invite: the person sets their own password through a one-time
// link. Only the SHA-256 of the token is stored. Until they accept, the
// account has a random unknown password, so it cannot be signed into.
// A one-time link through which the person sets their own password.
// Only the SHA-256 of the token is stored.
// invite: a new account; until accepted it has a random unknown password.
// reset: a forgotten password; the old password keeps working until the
// link is used, and using it signs the account out everywhere.
// Rows from before invitePurpose existed have null, which means invite.
inviteTokenHash: string | null;
inviteExpiresAt: Date | null;
invitePurpose: "invite" | "reset" | null;
createdAt: Date;
updatedAt: Date;
@@ -51,6 +55,7 @@ const userSchema = new Schema<IUser>(
lockedUntil: { type: Date, default: null },
inviteTokenHash: { type: String, default: null, index: { sparse: true } },
inviteExpiresAt: { type: Date, default: null },
invitePurpose: { type: String, enum: ["invite", "reset", null], default: null },
},
{ timestamps: true }
);