Phase 10, part 3: signing in and out, resets, locks and two-factor
The server edition now starts. Sign-in by email and password, limited per address and per IP; ten failures in a row lock the account and email its owner, and a reset by email (or an admin) unlocks it. Settings → Your account has the profile, the password, where you're signed in, and two-factor sign-in with an authenticator app (TOTP, from a QR code) and ten recovery codes. The app's own mail goes through SUPERMARKET_MAIL_URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$d := .}}
|
||||
<h2>Your account</h2>
|
||||
<p class="lede">{{.U.Email}} · {{.Role}}{{if not .U.SignedIn.IsZero}} · signed in {{ago .U.SignedIn}}{{end}}</p>
|
||||
|
||||
<form class="card" method="post" action="/settings/account/profile" id="profile">
|
||||
<h2>About you</h2>
|
||||
{{if eq .Section "profile"}}<p class="error" role="alert">{{.Problem}}</p>{{end}}
|
||||
<div class="cols">
|
||||
<label>Name <input name="name" value="{{.U.Name}}" autocomplete="name" required></label>
|
||||
<label>Title <input name="title" value="{{.U.Title}}" placeholder="e.g. Head of marketing" autocomplete="organization-title"></label>
|
||||
</div>
|
||||
<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>
|
||||
<button type="submit">Save</button>
|
||||
</form>
|
||||
|
||||
<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}}
|
||||
<input type="text" name="username" value="{{.U.Email}}" autocomplete="username" hidden>
|
||||
<label>Current password <input type="password" name="current" autocomplete="current-password" required></label>
|
||||
<div class="cols">
|
||||
<label>New password <input type="password" name="password" autocomplete="new-password" minlength="10" required>
|
||||
<span class="help">At least 10 characters.</span></label>
|
||||
<label>The new one again <input type="password" name="password2" autocomplete="new-password" minlength="10" required></label>
|
||||
</div>
|
||||
<p class="help">Changing it signs you out everywhere else.</p>
|
||||
<button type="submit">Change the password</button>
|
||||
</form>
|
||||
|
||||
<section class="card" id="two-factor">
|
||||
<h2>Two-factor sign-in</h2>
|
||||
{{if eq .Section "two-factor"}}<p class="error" role="alert">{{.Problem}}</p>{{end}}
|
||||
{{if .U.TwoFactor}}
|
||||
<p><span class="pill ok">On</span> Signing in asks for a code from your authenticator app.
|
||||
{{if lt .U.RecoveryLeft 3}}<strong>{{.U.RecoveryLeft}} recovery codes left:</strong> make new ones below.{{else}}{{.U.RecoveryLeft}} recovery codes left.{{end}}</p>
|
||||
<div class="cols">
|
||||
<form method="post" action="/settings/account/recovery-codes">
|
||||
<input type="text" name="username" value="{{.U.Email}}" autocomplete="username" hidden>
|
||||
<label>Your password <input type="password" name="current" autocomplete="current-password" required></label>
|
||||
<button type="submit" class="secondary">New recovery codes</button>
|
||||
</form>
|
||||
<form method="post" action="/settings/account/two-factor/off">
|
||||
<input type="text" name="username" value="{{.U.Email}}" autocomplete="username" hidden>
|
||||
<label>Your password <input type="password" name="current" autocomplete="current-password" required></label>
|
||||
<button type="submit" class="secondary danger">Turn it off</button>
|
||||
</form>
|
||||
</div>
|
||||
{{else}}
|
||||
<p>Off. With it on, signing in asks for your password and a code from an authenticator app on your phone (such as Aegis, 2FAS, Google Authenticator or 1Password), so a stolen password isn't enough.</p>
|
||||
<a class="button" href="/settings/account/two-factor">Turn it on</a>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<section class="card" id="sessions">
|
||||
<h2>Where you're signed in</h2>
|
||||
<table class="list">
|
||||
<thead><tr><th>Browser</th><th>From</th><th>Signed in</th><th>Last used</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Sessions}}<tr>
|
||||
<td>{{if .UserAgent}}{{truncate 60 .UserAgent}}{{else}}<span class="muted">unknown</span>{{end}}{{if .This}} <span class="pill">this one</span>{{end}}</td>
|
||||
<td>{{.IP}}</td><td>{{ago .Created}}</td><td>{{ago .Seen}}</td>
|
||||
<td><form class="inline" method="post" action="/settings/account/sessions/{{.ID}}/end"><button type="submit" class="secondary small">Sign out</button></form></td>
|
||||
</tr>{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{if gt (len .Sessions) 1}}<form method="post" action="/settings/account/sessions/end-others"><button type="submit" class="secondary">Sign out everywhere else</button></form>{{end}}
|
||||
</section>
|
||||
{{end}}{{template "settings-end"}}{{end}}
|
||||
@@ -0,0 +1,29 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
{{if .Reset}}
|
||||
<h1>Choose a new password</h1>
|
||||
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
|
||||
<form class="card" method="post" action="/reset/{{.Reset}}">
|
||||
<label>New password <input type="password" name="password" autocomplete="new-password" minlength="10" required autofocus>
|
||||
<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>
|
||||
<button type="submit">Save the new password</button>
|
||||
</form>
|
||||
<p class="help">Every place you're signed in is signed out; then you sign in with the new password.</p>
|
||||
{{else if .Sent}}
|
||||
<h1>Check your email</h1>
|
||||
<section class="card">
|
||||
<p>If there's an account for <strong>{{.Email}}</strong>, a link to choose a new password is on its way. It works once, for an hour.</p>
|
||||
<p class="help">Nothing after a few minutes? Check the spam folder, and that the address is the one you sign in with.</p>
|
||||
</section>
|
||||
<p class="help"><a href="/signin">Back to signing in</a></p>
|
||||
{{else}}
|
||||
<h1>Reset your password</h1>
|
||||
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
|
||||
<form class="card" method="post" action="/forgot">
|
||||
<label>Your email address <input type="email" name="email" value="{{.Email}}" autocomplete="username" required autofocus>
|
||||
<span class="help">We'll email you a link to choose a new one. Resetting also unlocks a locked account.</span></label>
|
||||
<button type="submit">Send the link</button>
|
||||
</form>
|
||||
<p class="help"><a href="/signin">Back to signing in</a></p>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -102,6 +102,8 @@
|
||||
</nav>
|
||||
<div class="sidebar-foot">
|
||||
<a href="/settings/profile" {{if hasPrefix .Nav "settings"}}aria-current="page"{{end}}>{{template "icon" "settings"}}<span>Settings</span></a>
|
||||
{{with .Viewer}}{{with .User}}<div class="who"><a href="/settings/account" title="Your account">{{if .Name}}{{.Name}}{{else}}{{.Email}}{{end}}</a>
|
||||
<form method="post" action="/signout"><button type="submit" class="secondary small">Sign out</button></form></div>{{end}}{{end}}
|
||||
<p class="version">Supermarket {{.Version}}</p>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -136,6 +138,8 @@
|
||||
</div>
|
||||
<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}}
|
||||
<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>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
{{if .Code}}
|
||||
<h1>Two-factor sign-in</h1>
|
||||
<p class="lede">Enter the six-digit code your authenticator app shows for Supermarket.</p>
|
||||
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
|
||||
<form class="card" method="post" action="/signin/code">
|
||||
<input type="hidden" name="token" value="{{.Token}}">
|
||||
<input type="hidden" name="next" value="{{.Next}}">
|
||||
<label>Code <input name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9 ]{6,7}|[A-Za-z0-9 -]{12,16}" required autofocus>
|
||||
<span class="help">Lost your phone? Enter one of your recovery codes instead.</span></label>
|
||||
<button type="submit">Sign in</button>
|
||||
</form>
|
||||
<p class="help"><a href="/signin">Start again</a></p>
|
||||
{{else}}
|
||||
<h1>Sign in</h1>
|
||||
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
|
||||
<form class="card" method="post" action="/signin">
|
||||
<input type="hidden" name="next" value="{{.Next}}">
|
||||
<label>Email address <input type="email" name="email" value="{{.Email}}" autocomplete="username" required {{if not .Email}}autofocus{{end}}></label>
|
||||
<label>Password <input type="password" name="password" autocomplete="current-password" required {{if .Email}}autofocus{{end}}></label>
|
||||
<button type="submit">Sign in</button>
|
||||
</form>
|
||||
<p class="help"><a href="/forgot{{with .Email}}?email={{.}}{{end}}">Forgotten your password?</a></p>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -0,0 +1,29 @@
|
||||
{{define "content"}}{{template "settings-start" .}}{{with .Data}}
|
||||
<h2>Two-factor sign-in</h2>
|
||||
{{if .Codes}}
|
||||
<section class="card">
|
||||
<h2>Your recovery codes</h2>
|
||||
<p>If you lose your phone, each of these signs you in once instead of a code. <strong>Save them now</strong> (in a password manager, or printed): they aren't shown again.</p>
|
||||
<pre id="codes">{{range .Codes}}{{.}}
|
||||
{{end}}</pre>
|
||||
<button type="button" class="secondary" data-copy="codes">Copy</button>
|
||||
<p><a class="button" href="/settings/account#two-factor">Done</a></p>
|
||||
</section>
|
||||
{{else}}
|
||||
<section class="card">
|
||||
<ol>
|
||||
<li>Open your authenticator app and add an account, by scanning this code:
|
||||
{{with .QR}}<p><img src="{{.}}" alt="QR code to add Supermarket to an authenticator app" width="246" height="246" class="qr"></p>{{end}}
|
||||
<p class="help">Or type this key: <code>{{.Secret}}</code> (time-based).</p></li>
|
||||
<li>Enter the six-digit code the app shows:
|
||||
<form method="post" action="/settings/account/two-factor">
|
||||
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
|
||||
<label>Code <input name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9 ]{6,7}" required autofocus></label>
|
||||
<button type="submit">Turn on two-factor sign-in</button>
|
||||
</form>
|
||||
</li>
|
||||
</ol>
|
||||
<p class="help">Then you get ten recovery codes, for when you don't have your phone. <a href="/settings/account">Cancel</a></p>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}{{template "settings-end"}}{{end}}
|
||||
Reference in New Issue
Block a user