Phase 1: app, Kanidm login, people, passports, addresses, audit log
CI / secret scan (push) Successful in 4s
CI / fmt, clippy, tests (push) Successful in 42s

visa.buildfor.life keeps the immigration records of the foreigners B4L
looks after. This first phase is the base the deadlines and extension
packs build on (docs/PLAN.md, phases 2 to 7).

- One Rust binary (axum 0.8, minijinja, sqlx on PostgreSQL) with its
  templates, static files and migrations compiled in.
- Login through Kanidm (OpenID Connect with PKCE and a nonce, ES256),
  client visa-web, group visa; sessions in PostgreSQL keyed by the
  SHA-256 of the cookie. VISA_INSECURE_NO_LOGIN=1 for loopback
  development only.
- Same-site check and form token on every POST; a CSP without inline
  script or style; security headers.
- People: list with filter, page, create, edit, archive, restore.
- Passports from the machine-readable zone with check digits (ICAO
  9303 TD3); expiry warnings at 12 and 6 months.
- Addresses in Thailand in the order Thai forms use, with the house
  master and the TM.30 receipt.
- Append-only audit log of every view and change, with the names of the
  changed fields but never their values (PDPA); the Activity page.
- Invented demo people (visa seed-demo, refused when login is on).
- 40 tests: unit tests, pages with demo data, the forms, the audit log
  and the whole login against a fake OpenID provider.
- CI: gitleaks over the history, fmt, clippy and the tests against
  PostgreSQL 18; the pre-commit secret scan.
This commit is contained in:
grabowski committed 2026-11-17 16:58:48 +07:00
commit 2e009700a9
56 files changed
+11193

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
{#- Form fields. Every field has a label, its error under it and the
error tied to the input for screen readers. -#}
{% macro text(name, label, value="", err="", hint="", req=false, type="text", list="", auto="off", cls="", ph="") -%}
<div class="field{% if err %} has-err{% endif %}{% if cls %} {{ cls }}{% endif %}">
<label for="f-{{ name }}">{{ label }}{% if req %} <span class="req" aria-hidden="true">*</span>{% endif %}</label>
<input id="f-{{ name }}" name="{{ name }}" type="{{ type }}" value="{{ value }}"{% if req %} required{% endif %}{% if list %} list="{{ list }}"{% endif %} autocomplete="{{ auto }}"{% if ph %} placeholder="{{ ph }}"{% endif %}{% if err %} aria-invalid="true" aria-describedby="e-{{ name }}"{% elif hint %} aria-describedby="h-{{ name }}"{% endif %}>
{%- if hint %}
<p class="hint" id="h-{{ name }}">{{ hint }}</p>
{%- endif %}
{%- if err %}
<p class="err" id="e-{{ name }}">{{ err }}</p>
{%- endif %}
</div>
{%- endmacro %}
{% macro select(name, label, value, options, err="", hint="", blank="Not recorded", cls="") -%}
<div class="field{% if err %} has-err{% endif %}{% if cls %} {{ cls }}{% endif %}">
<label for="f-{{ name }}">{{ label }}</label>
<select id="f-{{ name }}" name="{{ name }}"{% if err %} aria-invalid="true" aria-describedby="e-{{ name }}"{% endif %}>
<option value="">{{ blank }}</option>
{%- for o in options %}
<option value="{{ o[0] }}"{% if o[0] == value %} selected{% endif %}>{{ o[1] }}</option>
{%- endfor %}
</select>
{%- if hint %}
<p class="hint">{{ hint }}</p>
{%- endif %}
{%- if err %}
<p class="err" id="e-{{ name }}">{{ err }}</p>
{%- endif %}
</div>
{%- endmacro %}
{% macro area(name, label, value="", err="", hint="", rows=3, cls="", fcls="") -%}
<div class="field{% if err %} has-err{% endif %}{% if fcls %} {{ fcls }}{% endif %}">
<label for="f-{{ name }}">{{ label }}</label>
<textarea id="f-{{ name }}" name="{{ name }}" rows="{{ rows }}"{% if cls %} class="{{ cls }}"{% endif %} spellcheck="false"{% if err %} aria-invalid="true" aria-describedby="e-{{ name }}"{% endif %}>{{ value }}</textarea>
{%- if hint %}
<p class="hint">{{ hint }}</p>
{%- endif %}
{%- if err %}
<p class="err" id="e-{{ name }}">{{ err }}</p>
{%- endif %}
</div>
{%- endmacro %}
+1
View File
@@ -0,0 +1 @@
<svg class="mark" viewBox="0 0 64 64" aria-hidden="true"><rect x="1" y="1" width="62" height="62" rx="14" fill="#0d2240" stroke="#f5c000" stroke-opacity=".6" stroke-width="2"/><text x="32" y="41" text-anchor="middle" font-family="Montserrat, 'Arial Black', 'Segoe UI', sans-serif" font-weight="900" font-size="24" letter-spacing="1"><tspan fill="#ffffff">B4</tspan><tspan fill="#f5c000">L</tspan></text></svg>

After

Width:  |  Height:  |  Size: 410 B

+23
View File
@@ -0,0 +1,23 @@
{#- The head of every page about one person: the same place on each. -#}
<div class="phead">
<div class="crumbs"><a href="/people">People</a></div>
<div class="pagehead">
<h1><a href="/people/{{ p.id }}">{{ p.name }}</a></h1>
<div class="actions">
{% if p.archived %}
<form method="post" action="/people/{{ p.id }}/restore" class="inline-form"><input type="hidden" name="csrf" value="{{ csrf }}"><button type="submit" class="btn sm">Restore</button></form>
{% else %}
<form method="post" action="/people/{{ p.id }}/archive" class="inline-form" data-confirm="Archive {{ p.name }}? The record stays and can be restored."><input type="hidden" name="csrf" value="{{ csrf }}"><button type="submit" class="btn sm ghost">Archive</button></form>
{% endif %}
</div>
</div>
<p class="meta">
{%- if p.nationality_name %}{{ p.nationality_name }}{% else %}Nationality not recorded{% endif %}
{%- if p.age is not none %}<span class="sep">·</span>{{ p.age }} years{% endif %}
{%- if p.current_passport %}<span class="sep">·</span>passport <span class="mono">{{ p.current_passport }}</span>{% endif %}
{%- if p.employer %}<span class="sep">·</span>{{ p.employer }}{% endif %}
</p>
</div>
{% if p.archived %}
<div class="notice warn">Archived on {{ p.archived_on }}. Archived people are left out of the list; Restore brings the record back.</div>
{% endif %}
+30
View File
@@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block main %}
<div class="pagehead">
<h1>Activity{% if person %}: <a href="/people/{{ person.id }}">{{ person.name }}</a>{% endif %}</h1>
{% if person %}<div class="actions"><a class="btn sm ghost" href="/activity">Everyone</a></div>{% endif %}
</div>
<p class="muted">Every view and change of a person's record, newest first: who, when and which fields changed (never their values). The log cannot be edited.</p>
{% if items %}
<div class="card flush">
<div class="tblwrap">
<table class="tbl" id="activity">
<thead><tr><th>When</th><th>Who</th><th>Did</th><th>Record</th><th class="hs">Fields</th></tr></thead>
<tbody>
{% for e in items %}
<tr>
<td class="mono">{{ e.at }}</td>
<td>{{ e.actor }}</td>
<td>{{ e.action }}</td>
<td>{% if e.person_id %}<a href="/people/{{ e.person_id }}">{{ e.person_name or ("person " ~ e.person_id) }}</a> <span class="muted">{{ e.what }}</span>{% else %}<span class="muted">{{ e.what }}</span>{% endif %}</td>
<td class="hs muted">{{ e.fields }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% else %}
<div class="card"><p class="empty-inline">Nothing has happened yet.</p></div>
{% endif %}
{% endblock %}
+47
View File
@@ -0,0 +1,47 @@
{% extends "base.html" %}
{% import "_fields.html" as fm %}
{% block main %}
{% include "_person_head.html" %}
<form method="post" action="{{ action }}" class="form" id="address-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<section class="card">
<header><h2>{{ heading }}</h2></header>
<p class="hint lead">In the order Thai forms use. Leave out what the address does not have.</p>
<div class="grid">
{{ fm.text("house_no", "House number", af.house_no, err=errors.house_no, ph="99/9") }}
{{ fm.text("moo", "Moo (village number)", af.moo, err=errors.moo) }}
{{ fm.text("building", "Village, building or condominium", af.building, err=errors.building, hint="With the room number, if any.", cls="wide") }}
{{ fm.text("soi", "Soi", af.soi, err=errors.soi) }}
{{ fm.text("road", "Road", af.road, err=errors.road) }}
{{ fm.text("subdistrict", "Subdistrict (tambon)", af.subdistrict, err=errors.subdistrict) }}
{{ fm.text("district", "District (amphoe)", af.district, err=errors.district, req=true) }}
{{ fm.text("province", "Province", af.province, err=errors.province, req=true, list="provinces") }}
{{ fm.text("postal_code", "Postal code", af.postal_code, err=errors.postal_code) }}
{{ fm.text("moved_in_on", "Moved in on", af.moved_in_on, err=errors.moved_in_on, type="date") }}
{{ fm.text("moved_out_on", "Moved out on", af.moved_out_on, err=errors.moved_out_on, type="date", hint="Empty while the person lives here.") }}
</div>
</section>
<section class="card">
<header><h2>House master and TM.30</h2></header>
<p class="hint lead">The owner or landlord reports the person's address on form TM.30 within 24 hours of arrival, also after every trip abroad. Extensions of stay and 90-day reports ask for the receipt.</p>
<div class="grid">
{{ fm.text("house_master", "House master", af.house_master, err=errors.house_master, hint="The owner or landlord who files TM.30.") }}
{{ fm.text("house_master_phone", "House master's phone", af.house_master_phone, err=errors.house_master_phone, type="tel") }}
{{ fm.text("tm30_reported_on", "TM.30 reported on", af.tm30_reported_on, err=errors.tm30_reported_on, type="date") }}
{{ fm.text("tm30_receipt_no", "TM.30 receipt number", af.tm30_receipt_no, err=errors.tm30_receipt_no) }}
</div>
</section>
<div class="formactions">
<button type="submit" class="btn pri" id="save">Save</button>
<a class="btn ghost" href="/people/{{ p.id }}#addresses">Cancel</a>
</div>
</form>
<datalist id="provinces">{% for pv in provinces %}<option value="{{ pv }}"></option>{% endfor %}</datalist>
{% if mode == "edit" %}
<form method="post" action="{{ action }}/delete" class="dangerzone" data-confirm="Delete this address from the record?">
<input type="hidden" name="csrf" value="{{ csrf }}">
<button type="submit" class="btn sm danger">Delete this address</button>
<span class="muted small">For an address entered by mistake. When the person moves, set the move-out date instead and add the new address.</span>
</form>
{% endif %}
{% endblock %}
+46
View File
@@ -0,0 +1,46 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title>{{ title }} · visa.buildfor.life</title>
<script src="/static/theme-init.js?v={{ v }}"></script>
<link rel="icon" href="/static/favicon.svg?v={{ v }}" type="image/svg+xml">
<link rel="stylesheet" href="/static/app.css?v={{ v }}">
<script src="/static/app.js?v={{ v }}" defer></script>
</head>
<body>
<header class="top">
<a class="brand" href="/people" aria-label="visa.buildfor.life, the people">
{% include "_mark.html" %}
<span class="nm">Visa</span><span class="sub">buildfor.life</span>
</a>
<button type="button" class="ib" id="themeBtn" aria-label="Switch between light and dark" title="Switch between light and dark">&#9680;</button>
</header>
<div class="app">
<aside class="side">
<nav class="nav" aria-label="Sections">
<a href="/people"{% if nav == "people" %} class="on" aria-current="page"{% endif %}>People</a>
<a href="/activity"{% if nav == "activity" %} class="on" aria-current="page"{% endif %}>Activity</a>
</nav>
<div class="who">
{% if user.local %}
<span class="k">Local development</span>
<b>No login</b>
<p>VISA_INSECURE_NO_LOGIN is set; this only runs on a loopback address.</p>
{% else %}
<span class="k">Signed in as</span>
<b>{{ user.name }}</b>
<p>{{ user.login }} at id.cnx.network</p>
<form method="post" action="/logout" class="inline-form"><input type="hidden" name="csrf" value="{{ csrf }}"><button type="submit" class="btn sm ghost">Sign out</button></form>
{% endif %}
</div>
</aside>
<main id="main">
{% block main %}{% endblock %}
<footer class="ft">visa.buildfor.life {{ version }}. Every view and change of a person's record is written to the Activity log. Dates are in Chiang Mai time.</footer>
</main>
</div>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title>{{ title }} · visa.buildfor.life</title>
<script src="/static/theme-init.js?v={{ v }}"></script>
<link rel="icon" href="/static/favicon.svg?v={{ v }}" type="image/svg+xml">
<link rel="stylesheet" href="/static/app.css?v={{ v }}">
<script src="/static/app.js?v={{ v }}" defer></script>
</head>
<body>
<header class="top">
<a class="brand" href="/">{% include "_mark.html" %}<span class="nm">Visa</span><span class="sub">buildfor.life</span></a>
<button type="button" class="ib" id="themeBtn" aria-label="Switch between light and dark" title="Switch between light and dark">&#9680;</button>
</header>
<main class="solo">
<div class="card">
<div class="eyebrow">visa.buildfor.life</div>
<h1>{{ title }}</h1>
<p>{{ text }}</p>
<p><a class="btn pri" href="{{ href }}">{{ link }}</a></p>
</div>
</main>
</body>
</html>
+40
View File
@@ -0,0 +1,40 @@
{% extends "base.html" %}
{% import "_fields.html" as fm %}
{% block main %}
{% include "_person_head.html" %}
<form method="post" action="{{ action }}" class="form" id="passport-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<button type="submit" name="action" value="save" class="default-submit" tabindex="-1" aria-hidden="true">Save</button>
<section class="card" id="mrz-card">
<header><h2>{{ heading }}</h2></header>
<p class="hint lead">Type or paste the two lines at the bottom of the photo page and press Read to fill in the fields below.</p>
{{ fm.area("mrz", "Machine-readable zone, two lines of 44 characters", pf.mrz, err=errors.mrz, rows=2, cls="mrz") }}
<div class="formactions">
<button type="submit" name="action" value="read-mrz" class="btn" id="read-mrz" formnovalidate>Read</button>
{% if mrz_note %}<p class="okline" role="status">{{ mrz_note }}</p>{% endif %}
</div>
{% if name_hint %}<p class="hintline" role="status">{{ name_hint }}</p>{% endif %}
</section>
<section class="card">
<header><h2>Passport</h2></header>
<div class="grid">
{{ fm.text("number", "Passport number", pf.number, err=errors.number, req=true) }}
{{ fm.select("issuing_country", "Issued by", pf.issuing_country, countries, err=errors.issuing_country, blank="Choose a country") }}
{{ fm.text("issued_on", "Date of issue", pf.issued_on, err=errors.issued_on, type="date") }}
{{ fm.text("expires_on", "Date of expiry", pf.expires_on, err=errors.expires_on, type="date", req=true) }}
{{ fm.text("issued_at", "Authority or place of issue", pf.issued_at, err=errors.issued_at, hint="As printed in the passport.", cls="wide") }}
</div>
</section>
<div class="formactions">
<button type="submit" name="action" value="save" class="btn pri" id="save">Save</button>
<a class="btn ghost" href="/people/{{ p.id }}#passports">Cancel</a>
</div>
</form>
{% if mode == "edit" %}
<form method="post" action="{{ action }}/delete" class="dangerzone" data-confirm="Delete this passport from the record?">
<input type="hidden" name="csrf" value="{{ csrf }}">
<button type="submit" class="btn sm danger">Delete this passport</button>
<span class="muted small">For a passport entered by mistake. An expired passport stays on the record as a previous one.</span>
</form>
{% endif %}
{% endblock %}
+44
View File
@@ -0,0 +1,44 @@
{% extends "base.html" %}
{% block main %}
<div class="pagehead">
<h1>{% if archived %}Archived people{% else %}People{% endif %}</h1>
<div class="actions"><a class="btn pri" href="/people/new" id="new-person">+ New person</a></div>
</div>
{% if people or n_archived %}
<div class="toolbar">
{% if people %}<input type="search" id="q" class="filter" placeholder="Filter by name, passport, nationality or employer ( / )" aria-label="Filter the list" autocomplete="off">{% endif %}
{% if archived %}<a href="/people">Back to the {{ n_active }} in the list</a>{% elif n_archived %}<a href="/people?archived=1">Archived ({{ n_archived }})</a>{% endif %}
</div>
{% endif %}
{% if people %}
<div class="card flush">
<div class="tblwrap">
<table class="tbl" id="people">
<thead>
<tr><th>Name</th><th class="hs">Nationality</th><th>Passport</th><th>Valid until</th><th class="hs">Lives in</th><th class="hs">Employer</th></tr>
</thead>
<tbody>
{% for r in people %}
<tr data-q="{{ r.q }}">
<td><a class="strong" href="/people/{{ r.id }}">{{ r.name }}</a>{% if r.age is not none %}<div class="sub">{{ r.age }} years</div>{% endif %}</td>
<td class="hs">{{ r.nationality }}</td>
<td>{% if r.passport_number %}<span class="mono">{{ r.passport_number }}</span>{% else %}<span class="muted">none recorded</span>{% endif %}</td>
<td>{% if r.passport_status %}{{ r.passport_expires }}<div><span class="chip {{ r.passport_status.level }}">{{ r.passport_status.label }}</span></div>{% endif %}</td>
<td class="hs">{{ r.province }}</td>
<td class="hs">{{ r.employer }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<p class="filter-empty" data-filter-empty hidden>No one in the list matches the filter.</p>
</div>
{% elif archived %}
<div class="card"><p class="empty-inline">No one is archived.</p></div>
{% else %}
<div class="card">
<h2>No people yet</h2>
<p>Add the first person with <b>+ New person</b>. Paste the two lines at the bottom of the passport's photo page there, and the form fills in the name, nationality, date of birth and the passport itself.</p>
</div>
{% endif %}
{% endblock %}
+74
View File
@@ -0,0 +1,74 @@
{% extends "base.html" %}
{% block main %}
{% include "_person_head.html" %}
<div class="cols">
<section class="card" id="details">
<header><h2>Personal details</h2><a class="btn sm" href="/people/{{ p.id }}/edit">Edit</a></header>
<dl class="kv">
<dt>Surname</dt><dd>{{ p.surname }}</dd>
<dt>Given names</dt><dd>{{ p.given }}</dd>
{% if p.title %}<dt>Title</dt><dd>{{ p.title }}</dd>{% endif %}
<dt>Sex</dt><dd>{% if p.sex %}{{ p.sex }}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Date of birth</dt><dd>{% if p.dob %}{{ p.dob }} <span class="muted">({{ p.age }} years)</span>{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Place of birth</dt><dd>{% if p.place_of_birth %}{{ p.place_of_birth }}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Nationality</dt><dd>{% if p.nationality %}{{ p.nationality_name }} <span class="muted mono">{{ p.nationality }}</span>{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Occupation</dt><dd>{% if p.occupation %}{{ p.occupation }}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Employer</dt><dd>{% if p.employer %}{{ p.employer }}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Phone</dt><dd>{% if p.phone %}{{ p.phone }}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>Email</dt><dd>{% if p.email %}{{ p.email }}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
{% if p.notes %}<dt>Notes</dt><dd class="pre">{{ p.notes }}</dd>{% endif %}
</dl>
</section>
<section class="card" id="passports">
<header><h2>Passport</h2><a class="btn sm" href="/people/{{ p.id }}/passports/new">+ New passport</a></header>
{% for pp in passports %}
<div class="item{% if not pp.current %} old{% endif %}">
<div class="row">
<span class="mono strong">{{ pp.number }}</span>
<span class="muted">{{ pp.country_name }}</span>
{% if pp.current %}<span class="tag">current</span>{% else %}<span class="tag plain">previous</span>{% endif %}
</div>
<dl class="kv">
<dt>Issued</dt><dd>{% if pp.issued_on %}{{ pp.issued_on }}{% else %}<span class="muted">date not recorded</span>{% endif %}{% if pp.issued_at %}, {{ pp.issued_at }}{% endif %}</dd>
<dt>Valid until</dt><dd>{{ pp.expires_on }}{% if pp.status %} <span class="chip {{ pp.status.level }}">{{ pp.status.label }}</span>{% endif %}</dd>
<dt>Zone</dt><dd>{% if pp.has_mrz %}read, check digits matched{% else %}<span class="muted">typed in by hand</span>{% endif %}</dd>
</dl>
<div class="rowactions"><a href="/people/{{ p.id }}/passports/{{ pp.id }}/edit">Edit</a></div>
</div>
{% else %}
<p class="empty-inline">No passport recorded yet. Add it with + New passport; the two lines at the bottom of the photo page fill the form in.</p>
{% endfor %}
</section>
<section class="card" id="addresses">
<header><h2>Address in Thailand</h2><a class="btn sm" href="/people/{{ p.id }}/addresses/new">+ New address</a></header>
{% for a in addresses %}
<div class="item{% if not a.current %} old{% endif %}">
<div class="row">
{% if a.current %}<span class="tag">current</span>{% else %}<span class="tag plain">earlier</span>{% endif %}
<span class="muted small">{% if a.moved_in_on %}since {{ a.moved_in_on }}{% endif %}{% if a.moved_out_on %} until {{ a.moved_out_on }}{% endif %}</span>
</div>
<p class="addr">{{ a.line }}</p>
<dl class="kv">
<dt>House master</dt><dd>{% if a.house_master %}{{ a.house_master }}{% if a.house_master_phone %}, {{ a.house_master_phone }}{% endif %}{% else %}<span class="muted">not recorded</span>{% endif %}</dd>
<dt>TM.30</dt><dd>{% if a.tm30_reported_on %}reported {{ a.tm30_reported_on }}{% if a.tm30_receipt_no %}, receipt <span class="mono">{{ a.tm30_receipt_no }}</span>{% endif %}{% else %}<span class="muted">no receipt recorded</span>{% endif %}
{% if a.tm30 %}<div><span class="chip {{ a.tm30.level }}">{{ a.tm30.label }}</span></div>{% endif %}</dd>
</dl>
<div class="rowactions"><a href="/people/{{ p.id }}/addresses/{{ a.id }}/edit">Edit</a></div>
</div>
{% else %}
<p class="empty-inline">No address recorded yet. The TM.30 receipt of the current address goes with it.</p>
{% endfor %}
</section>
<section class="card" id="recent">
<header><h2>Recent activity</h2><a class="btn sm ghost" href="/activity?person={{ p.id }}">All of it</a></header>
<ul class="log">
{% for e in recent %}
<li><span class="when">{{ e.at }}</span><span><b>{{ e.actor }}</b> {{ e.action }} {{ e.what }}{% if e.fields %} <span class="muted">({{ e.fields }})</span>{% endif %}</span></li>
{% endfor %}
</ul>
</section>
</div>
{% endblock %}
+59
View File
@@ -0,0 +1,59 @@
{% extends "base.html" %}
{% import "_fields.html" as fm %}
{% block main %}
{% if p %}
{% include "_person_head.html" %}
{% else %}
<div class="crumbs"><a href="/people">People</a></div>
<div class="pagehead"><h1>New person</h1></div>
{% endif %}
<form method="post" action="{{ action }}" class="form" id="person-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<button type="submit" name="action" value="save" class="default-submit" tabindex="-1" aria-hidden="true">Save</button>
{% if mode == "new" %}
<section class="card" id="mrz-card">
<header><h2>Read the passport</h2></header>
<p class="hint lead">Type or paste the two lines at the bottom of the photo page, then press Read. The form below fills itself in, and the check digits in the lines catch typing errors.</p>
{{ fm.area("mrz", "Machine-readable zone, two lines of 44 characters", pf.mrz, err=errors.mrz, rows=2, cls="mrz") }}
<div class="formactions">
<button type="submit" name="action" value="read-mrz" class="btn" id="read-mrz" formnovalidate>Read</button>
{% if mrz_note %}<p class="okline" role="status">{{ mrz_note }}</p>{% endif %}
</div>
</section>
{% endif %}
<section class="card">
<header><h2>{% if mode == "new" %}Person{% else %}Personal details{% endif %}</h2></header>
<div class="grid">
{{ fm.text("surname", "Surname", f.surname, err=errors.surname, req=true, hint="As printed in the passport.") }}
{{ fm.text("first_name", "First name", f.first_name, err=errors.first_name, req=true) }}
{{ fm.text("middle_name", "Middle names", f.middle_name, err=errors.middle_name) }}
{{ fm.select("title", "Title", f.title, titles, err=errors.title) }}
{{ fm.select("sex", "Sex", f.sex, sexes, err=errors.sex) }}
{{ fm.text("date_of_birth", "Date of birth", f.date_of_birth, err=errors.date_of_birth, type="date") }}
{{ fm.text("place_of_birth", "Place of birth", f.place_of_birth, err=errors.place_of_birth) }}
{{ fm.select("nationality", "Nationality", f.nationality, countries, err=errors.nationality) }}
{{ fm.text("occupation", "Occupation", f.occupation, err=errors.occupation) }}
{{ fm.text("employer", "Employer", f.employer, err=errors.employer, hint="The company named in the work permit.") }}
{{ fm.text("phone", "Phone", f.phone, err=errors.phone, type="tel") }}
{{ fm.text("email", "Email", f.email, err=errors.email, type="email") }}
{{ fm.area("notes", "Notes", f.notes, err=errors.notes, rows=3, fcls="wide") }}
</div>
</section>
{% if mode == "new" %}
<section class="card">
<header><h2>Passport</h2><span class="muted small">Optional here; it can also be added later.</span></header>
<div class="grid">
{{ fm.text("number", "Passport number", pf.number, err=errors.number) }}
{{ fm.select("issuing_country", "Issued by", pf.issuing_country, countries, err=errors.issuing_country, blank="Choose a country") }}
{{ fm.text("issued_on", "Date of issue", pf.issued_on, err=errors.issued_on, type="date") }}
{{ fm.text("expires_on", "Date of expiry", pf.expires_on, err=errors.expires_on, type="date") }}
{{ fm.text("issued_at", "Authority or place of issue", pf.issued_at, err=errors.issued_at, hint="As printed in the passport.", cls="wide") }}
</div>
</section>
{% endif %}
<div class="formactions">
<button type="submit" name="action" value="save" class="btn pri" id="save">{% if mode == "new" %}Create the person{% else %}Save{% endif %}</button>
<a class="btn ghost" href="{% if p %}/people/{{ p.id }}{% else %}/people{% endif %}">Cancel</a>
</div>
</form>
{% endblock %}