Phase 10, part 4: inviting users, and what admins can change

Settings → Users lists everyone with their access and status. Admins
invite people by email (a link for 7 days), as admins or as members with
modules each to view or edit; the invitation's page sets the password,
profile and emails wanted. Admins can resend or withdraw invitations,
change access, turn accounts off and on, unlock, reset two-factor, sign
someone out, and remove them; never the owner, nor themselves. Your
account gets the emails wanted and a photo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 09:07:32 -07:00
co-authored by Claude Opus 5.5
parent 8040512a18
commit 47a504b7b2
18 changed files with 1220 additions and 15 deletions
+19
View File
@@ -12,9 +12,28 @@
<label>Time zone <input name="time_zone" value="{{.U.TimeZone}}" list="zones" placeholder="e.g. Europe/Paris">
<span class="help">Times are shown in it. Empty: the server's.</span></label>
<datalist id="zones">{{range .Zones}}<option value="{{.}}">{{end}}</datalist>
{{if .Emails}}<fieldset>
<legend>Emails you'd like</legend>
{{$u := .U}}{{range .Emails}}<label class="check"><input type="checkbox" name="emails" value="{{.ID}}" {{if has $u.Emails .ID}}checked{{end}}> <span>{{.Name}} <span class="help">{{.Help}}</span></span></label>{{end}}
</fieldset>{{end}}
<button type="submit">Save</button>
</form>
{{if .Photos}}
<section class="card" id="photo">
<h2>Photo</h2>
<div class="photo-row">
{{if .U.Photo}}<img class="avatar large" src="/users/{{.U.ID}}/photo" alt="Your photo" width="64" height="64">{{else}}<span class="avatar large none" aria-hidden="true">{{slice .U.Email 0 1}}</span>{{end}}
<form method="post" action="/settings/account/photo" enctype="multipart/form-data" class="inline-form">
<input type="file" name="photo" accept="image/png,image/jpeg,image/webp,image/gif" required>
<button type="submit" class="secondary">Upload</button>
</form>
{{if .U.Photo}}<form method="post" action="/settings/account/photo?remove=1"><button type="submit" class="secondary small">Remove</button></form>{{end}}
</div>
<p class="help">Shown beside your name to the team. A square picture of 2 MB or less.</p>
</section>
{{end}}
<form class="card" method="post" action="/settings/account/password" id="password">
<h2>Password</h2>
{{if eq .Section "password"}}<p class="error" role="alert">{{.Problem}}</p>{{end}}
+7
View File
@@ -0,0 +1,7 @@
{{define "content"}}
<div class="page-head"><h1>No access</h1></div>
<section class="card empty">
<p>This isn't in what you have access to. An admin can give it to you, under Settings → Users.</p>
<p><a href="/">Back to the Overview</a></p>
</section>
{{end}}
+28
View File
@@ -0,0 +1,28 @@
{{define "content"}}{{with .Data}}
{{if .U}}
<h1>Join {{.Company}}</h1>
<p class="lede">You're invited to Supermarket as <strong>{{.U.Email}}</strong>. Choose a password, and tell the team a little about you.</p>
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
<form class="card" method="post" action="/invite/{{.Token}}">
<input type="text" name="username" value="{{.U.Email}}" autocomplete="username" hidden>
<label>Your name <input name="name" value="{{.U.Name}}" autocomplete="name" required></label>
<label>Title <input name="title" value="{{.U.Title}}" placeholder="e.g. Content writer" autocomplete="organization-title"></label>
<label>Time zone <input name="time_zone" value="{{.U.TimeZone}}" list="zones" placeholder="e.g. Europe/Paris"></label>
<datalist id="zones">{{range .Zones}}<option value="{{.}}">{{end}}</datalist>
<label>Choose a password <input type="password" name="password" autocomplete="new-password" minlength="10" required>
<span class="help">At least 10 characters. A few unrelated words make a good one.</span></label>
<label>The same password again <input type="password" name="password2" autocomplete="new-password" minlength="10" required></label>
{{if .Emails}}<fieldset>
<legend>Emails you'd like</legend>
{{$u := .U}}{{range .Emails}}<label class="check"><input type="checkbox" name="emails" value="{{.ID}}" {{if has $u.Emails .ID}}checked{{end}}> <span>{{.Name}} <span class="help">{{.Help}}</span></span></label>{{end}}
</fieldset>{{end}}
<button type="submit">Join</button>
</form>
{{else}}
<h1>This invitation doesn't work</h1>
<section class="card">
<p>It has expired (an invitation lasts 7 days), was already used, or was withdrawn or replaced by a newer one.</p>
<p class="help">Ask whoever invited you to send it again. If you've joined already, <a href="/signin">sign in</a>.</p>
</section>
{{end}}
{{end}}{{end}}
+25 -1
View File
@@ -139,7 +139,8 @@
<div class="settings">
<nav class="settings-nav" aria-label="Settings sections">
{{with .Viewer}}{{if .User}}<div class="nav-label">You</div>
<a href="/settings/account" {{if eq $.Nav "settings/account"}}aria-current="page"{{end}}>{{template "icon" "profile"}}Your account</a>{{end}}{{end}}
<a href="/settings/account" {{if eq $.Nav "settings/account"}}aria-current="page"{{end}}>{{template "icon" "profile"}}Your account</a>
{{if .Member.Admin}}<a href="/settings/users" {{if eq $.Nav "settings/users"}}aria-current="page"{{end}}>{{template "icon" "prospects"}}Users</a>{{end}}{{end}}{{end}}
<div class="nav-label">Company</div>
<a href="/settings/profile" {{if eq .Nav "settings/profile"}}aria-current="page"{{end}}>{{template "icon" "profile"}}Profile</a>
<div class="nav-label">Connections</div>
@@ -271,3 +272,26 @@
{{else}}<p class="help">None this week.</p>{{end}}
</section>
{{end}}
{{/* Users (Settings → Users, and one user's page). */}}
{{define "user-status"}}{{if eq .Status "invited"}}{{if .InviteEnd.IsZero}}<span class="pill warn">Invitation expired</span>{{else}}<span class="pill">Invited</span> <span class="muted small">until {{.InviteEnd.Local.Format "2 Jan"}}</span>{{end}}{{else if eq .Status "disabled"}}<span class="pill">Turned off</span>{{else if .Locked}}<span class="pill warn">Locked</span>{{else}}<span class="pill ok">Active</span>{{if .TwoFactor}} <span class="muted small">two-factor</span>{{end}}{{end}}{{end}}
{{/* Role and modules: {{template "access-fields" (dict "Role" … "Modules" … "Grants" …)}} */}}
{{define "access-fields"}}{{$mods := .Modules}}
<fieldset class="access">
<legend>Access</legend>
<label class="check"><input type="radio" name="role" value="admin" {{if eq (print .Role) "admin"}}checked{{end}}> <span><strong>Admin</strong>: every module, Settings, users and connections</span></label>
<label class="check"><input type="radio" name="role" value="member" {{if ne (print .Role) "admin"}}checked{{end}}> <span><strong>Member</strong>: these modules</span></label>
<table class="list access-grid">
<tbody>
{{range .Grants}}{{$a := print (index $mods .ID)}}<tr>
<td>{{.Name}}</td>
<td><label class="check"><input type="radio" name="module:{{.ID}}" value="" {{if eq $a ""}}checked{{end}}> No access</label></td>
<td><label class="check"><input type="radio" name="module:{{.ID}}" value="view" {{if eq $a "view"}}checked{{end}}> View</label></td>
<td><label class="check"><input type="radio" name="module:{{.ID}}" value="edit" {{if eq $a "edit"}}checked{{end}}> Edit</label></td>
</tr>{{end}}
</tbody>
</table>
<p class="help">An admin has them all, whatever is chosen here. <em>View</em> shows a module's pages without the buttons and forms that change things.</p>
</fieldset>
{{end}}
+54
View File
@@ -0,0 +1,54 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$u := .M}}
<p><a href="/settings/users">← Users</a></p>
<h2>{{if $u.Name}}{{$u.Name}}{{else}}{{$u.Email}}{{end}}</h2>
<p class="lede">{{$u.Email}}{{with $u.Title}} · {{.}}{{end}} · {{template "user-status" $u}}</p>
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
<section class="card">
<dl class="facts">
<dt>Access</dt><dd>{{$u.Access}}</dd>
<dt>Joined</dt><dd>{{if eq $u.Status "invited"}}Not yet{{else}}{{$u.Created.Local.Format "2 Jan 2006"}}{{end}}</dd>
<dt>Last signed in</dt><dd>{{ago $u.SignedIn}}{{if .SessionsN}} · signed in on {{.SessionsN}} {{if eq .SessionsN 1}}browser{{else}}browsers{{end}}{{end}}</dd>
<dt>Two-factor sign-in</dt><dd>{{if $u.TwoFactor}}On, {{$u.RecoveryLeft}} recovery codes left{{else}}Off{{end}}</dd>
{{if $u.FailedSignIns}}<dt>Failed sign-ins</dt><dd>{{$u.FailedSignIns}} in a row{{if $u.Locked}}, locked {{ago $u.LockedAt}}{{end}}</dd>{{end}}
</dl>
</section>
{{if eq (print $u.Role) "owner"}}
<section class="card"><p class="help">The owner can do everything; their account can only be changed by them, under Settings → Your account.</p></section>
{{else if .Me}}
<section class="card"><p class="help">This is you: another admin changes your access. Your own settings are under <a href="/settings/account">Your account</a>.</p></section>
{{else}}
<form class="card" method="post" action="/settings/users/{{$u.ID}}/access">
{{template "access-fields" (dict "Role" $u.Role "Modules" $u.Modules "Grants" .Grants)}}
<button type="submit">Save</button>
</form>
<section class="card">
<h2>Account</h2>
<div class="actions">
{{if eq $u.Status "invited"}}
<form class="inline" method="post" action="/settings/users/{{$u.ID}}/resend"><button type="submit" class="secondary">Send the invitation again</button></form>
<form class="inline" method="post" action="/settings/users/{{$u.ID}}/withdraw"><button type="submit" class="secondary danger">Withdraw the invitation</button></form>
{{else if eq $u.Status "disabled"}}
<form class="inline" method="post" action="/settings/users/{{$u.ID}}/enable"><button type="submit" class="secondary">Turn the account back on</button></form>
{{else}}
{{if $u.Locked}}<form class="inline" method="post" action="/settings/users/{{$u.ID}}/unlock"><button type="submit">Unlock</button></form>{{end}}
{{if .SessionsN}}<form class="inline" method="post" action="/settings/users/{{$u.ID}}/sign-out"><button type="submit" class="secondary">Sign them out everywhere</button></form>{{end}}
{{if $u.TwoFactor}}<form class="inline" method="post" action="/settings/users/{{$u.ID}}/reset-two-factor"><button type="submit" class="secondary">Reset two-factor sign-in</button></form>{{end}}
<form class="inline" method="post" action="/settings/users/{{$u.ID}}/disable"><button type="submit" class="secondary danger">Turn the account off</button></form>
{{end}}
</div>
{{if $u.TwoFactor}}<p class="help">Reset two-factor sign-in for someone who lost their phone and their recovery codes: they sign in with their password alone, then turn it on again. Make sure it's really them asking.</p>{{end}}
<p class="help">Turning an account off signs them out and keeps their name on what they did; they can be turned back on.</p>
</section>
{{if ne $u.Status "invited"}}
<form class="card danger-zone" method="post" action="/settings/users/{{$u.ID}}/remove">
<h2>Remove</h2>
<p class="help">Removes the account for good. What they wrote stays.</p>
<button type="submit" class="danger">Remove {{if $u.Name}}{{$u.Name}}{{else}}{{$u.Email}}{{end}}</button>
</form>
{{end}}
{{end}}
{{end}}{{template "settings-end"}}{{end}}
+31
View File
@@ -0,0 +1,31 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$d := .}}
<h2>Users</h2>
<p class="lede">Who can sign in, and to what. Admins can do everything, including this page; members get the modules you give them, each to view or to edit.</p>
<section class="card">
<table class="list">
<thead><tr><th>Name</th><th>Access</th><th>Status</th><th>Last signed in</th></tr></thead>
<tbody>
{{range .Rows}}<tr>
<td><a href="/settings/users/{{.ID}}">{{if .Name}}{{.Name}}{{else}}{{.Email}}{{end}}</a>{{if eq .ID $d.Me}} <span class="muted">(you)</span>{{end}}<br><span class="muted small">{{.Email}}</span></td>
<td>{{.Access}}</td>
<td>{{template "user-status" .}}</td>
<td>{{ago .SignedIn}}</td>
</tr>{{end}}
</tbody>
</table>
</section>
<form class="card" method="post" action="/settings/users" id="invite">
<h2>Invite someone</h2>
{{with .Form.Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
<div class="cols">
<label>Email address <input type="email" name="email" value="{{.Form.Email}}" required></label>
<label>Name <input name="name" value="{{.Form.Name}}" required></label>
</div>
{{template "access-fields" (dict "Role" .Form.Role "Modules" .Form.Modules "Grants" .Grants)}}
<p class="help">They get an email with a link that works once, for 7 days, to choose a password and fill in their profile.</p>
<button type="submit">Send the invitation</button>
</form>
{{end}}{{template "settings-end"}}{{end}}