"""Account, authentication and policy-management views.
RECONSTRUCTION NOTICE. Insureon's customer portal is served from
`up.apps.insureon.com`, which returned HTTP 403 (awselb/2.0) for every request
from the capture environment. None of these screens is transcribed from
captured source pixels; only the site chrome, palette and typography around
them are. They carry no visual contract and are not acceptance-eligible.
See `KNOWN_DIFFERENCES.md`.
"""
from __future__ import annotations
from typing import Any, Mapping, Sequence
import render as R
ACCOUNT_NAV = [
("/account", "Overview"),
("/account/quotes", "Saved quotes"),
("/account/policies", "Policies"),
("/account/documents", "Documents"),
("/account/profile", "Profile & billing"),
]
TERMS_LINKS = (
'Terms of use and '
'Privacy policy'
)
def _auth_shell(inner: str, *, title: str, description: str = "") -> str:
body = f""""""
return R.page(body, title=title, description=description)
def _account_shell(inner: str, *, title: str, active: str,
account_name: str = "") -> str:
nav = "".join(
'{}'.format(
href, ' class="is-active"' if href == active else "", R.esc(label))
for href, label in ACCOUNT_NAV
)
body = f"""
My account
{R.esc(account_name)}
"""
return R.page(body, title=title, logged_in=True, account_name=account_name)
# --------------------------------------------------------------------------- #
# T16 sign-in
# --------------------------------------------------------------------------- #
def login(errors: Mapping[str, str] | None = None, email: str = "",
next_url: str = "", notice: str = "") -> str:
errors = errors or {}
inner = f"""
"""
return _auth_shell(inner, title="Log in | Insureon",
description="Log in to manage your Insureon policies and quotes.")
# --------------------------------------------------------------------------- #
# T17 registration
# --------------------------------------------------------------------------- #
def register(errors: Mapping[str, str] | None = None, values: Mapping[str, str] | None = None,
stage: str = "details", next_url: str = "", code_hint: str = "",
email: str = "") -> str:
errors = errors or {}
values = values or {}
if stage == "verify":
inner = f""""""
return _auth_shell(inner, title="Confirm your email | Insureon")
inner = f""""""
return _auth_shell(inner, title="Create an account | Insureon",
description="Create an Insureon account to save quotes and manage policies.")
# --------------------------------------------------------------------------- #
# T18 password recovery
# --------------------------------------------------------------------------- #
def forgot_password(errors: Mapping[str, str] | None = None, stage: str = "request",
email: str = "", code_hint: str = "", notice: str = "") -> str:
errors = errors or {}
back = (''
'Return to log in
')
if stage == "verify":
inner = f""""""
return _auth_shell(inner, title="Reset your password | Insureon")
inner = f""""""
return _auth_shell(inner, title="Reset your password | Insureon",
description="Reset the password on your Insureon account.")
# --------------------------------------------------------------------------- #
# portal
# --------------------------------------------------------------------------- #
def _record(title: str, meta: str, actions: Sequence[tuple[str, str]],
status: str = "", newest: bool = False) -> str:
acts = "".join(
f'{R.esc(label)}'
for label, href in actions
)
return f"""
{R.esc(title)}
{R.badge(status) if status else ''}
{R.esc(meta)}
{acts}
"""
def overview(account_name: str, applications: Sequence[Mapping[str, Any]],
policies: Sequence[Mapping[str, Any]],
documents: Sequence[Mapping[str, Any]]) -> str:
tiles = f""""""
recent = "".join(
_record(
f'{a.get("business_name") or "Untitled application"} — {a.get("profession_name", "")}',
f'{a.get("reference", "")} · updated {str(a.get("updated_at", ""))[:10]}',
[("Open", f'/app/quote/{a["id"]}/review')],
status=str(a.get("status", "")), newest=(i == 0),
)
for i, a in enumerate(applications[:5])
) or ''
inner = (tiles + "Recent activity
"
+ f'{recent}
')
return _account_shell(inner, title="My account | Insureon", active="/account",
account_name=account_name)
def quotes(account_name: str, applications: Sequence[Mapping[str, Any]],
notice: str = "") -> str:
"""T10 / T19: saved quotes, newest first, each with status and actions."""
rows = "".join(
_record(
f'{a.get("business_name") or "Untitled application"} — {a.get("profession_name", "")}',
f'{a.get("reference", "")} · {a.get("employees", "")} employees · '
f'{"$%s" % format(int(a["annual_revenue"]), ",") if a.get("annual_revenue") else "—"} revenue · '
f'saved {str(a.get("saved_at") or a.get("updated_at", ""))[:10]}',
[("View quotes", f'/app/quote/{a["id"]}/quotes'),
("Edit details", f'/app/quote/{a["id"]}/business'),
("Review", f'/app/quote/{a["id"]}/review')],
status=str(a.get("status", "")), newest=(i == 0),
)
for i, a in enumerate(applications)
) or ('You have not saved any quotes yet. '
'
Start a quote and save it to come back to it.
')
inner = (R.notice(notice)
+ "Saved quotes
"
+ "Open a saved quote to change an "
"input and recalculate your options.
"
+ f'{rows}
')
return _account_shell(inner, title="Saved quotes | Insureon",
active="/account/quotes", account_name=account_name)
def policies(account_name: str, rows: Sequence[Mapping[str, Any]],
notice: str = "") -> str:
"""T14: policy management — detail, billing, renewal, cancellation."""
items = "".join(
_record(
f'{p["product_name"]} — {p["carrier_name"]}',
f'Policy {p["number"]} · effective {p["effective_date"]} to '
f'{p["expiration_date"]} · {R.money(p["annual_premium_cents"])} / year',
[("Manage", f'/account/policies/{p["id"]}')],
status=str(p.get("status", "")), newest=(i == 0),
)
for i, p in enumerate(rows)
) or ('You have no policies yet. '
'
Get quotes to buy coverage.
')
inner = (R.notice(notice) + "Your policies
"
+ f'{items}
')
return _account_shell(inner, title="My policies | Insureon",
active="/account/policies", account_name=account_name)
def policy_detail(account_name: str, p: Mapping[str, Any],
documents: Sequence[Mapping[str, Any]], notice: str = "") -> str:
docs = "".join(
f'{R.esc(d["title"])}'
f' '
f'({R.esc(str(d.get("issued_at", ""))[:10])})'
for d in documents
) or "No documents issued for this policy yet."
active = str(p.get("status")) == "active"
cancel = f"""""" if active else ""
coi = f"""""" if active else ""
inner = f"""{R.notice(notice)}
← Back to policies
{R.esc(p["product_name"])} —
{R.esc(p["carrier_name"])} {R.badge(str(p.get("status", "")))}
| Policy number | {R.esc(p["number"])} |
| Carrier | {R.esc(p["carrier_name"])} |
| Status | {R.esc(str(p.get("status", "")).title())} |
| Effective date | {R.esc(p["effective_date"])} |
| Expiration date | {R.esc(p["expiration_date"])} |
| Annual premium |
{R.money(p["annual_premium_cents"])} |
"""
return _account_shell(inner, title=f"Policy {p['number']} | Insureon",
active="/account/policies", account_name=account_name)
def documents(account_name: str, rows: Sequence[Mapping[str, Any]]) -> str:
"""T13: policy/quote documents, summaries and proof of insurance."""
items = "".join(
_record(
d["title"],
f'{str(d.get("kind", "")).replace("-", " ").title()} · issued '
f'{str(d.get("issued_at", ""))[:10]}',
[("Open", f'/account/documents/{d["id"]}')],
newest=(i == 0),
)
for i, d in enumerate(rows)
) or ('No documents yet. Documents are issued when you '
'get quotes and when you buy a policy.
')
inner = ("Your documents
"
+ f'{items}
')
return _account_shell(inner, title="Documents | Insureon",
active="/account/documents", account_name=account_name)
def document_detail(account_name: str, d: Mapping[str, Any]) -> str:
inner = f"""← Back to documents
{R.esc(d["title"])}
{R.esc(str(d.get("kind", "")).replace("-", " ").title())} ·
issued {R.esc(str(d.get("issued_at", ""))[:10])}
{R.esc(d.get("body", ""))}
"""
return _account_shell(inner, title=f'{d["title"]} | Insureon',
active="/account/documents", account_name=account_name)
def profile(account_name: str, email: str, payments: Sequence[Mapping[str, Any]],
notice: str = "") -> str:
rows = "".join(
f'| {R.esc(str(p.get("created_at", ""))[:10])} | '
f'{R.money(p["amount_cents"])} · {R.esc(p.get("method_label", ""))} · '
f'{R.esc(str(p.get("status", "")).title())} |
'
for p in payments
) or '| No payments recorded. |
'
inner = f"""{R.notice(notice)}
Profile
Billing history
This offline demonstration site records local sandbox payments only. No card
details are collected, stored or transmitted.
"""
return _account_shell(inner, title="Profile & billing | Insureon",
active="/account/profile", account_name=account_name)
# --------------------------------------------------------------------------- #
# T20 permission prompt
# --------------------------------------------------------------------------- #
def sign_in_required(next_url: str, what: str = "this page") -> str:
inner = f""""""
return _auth_shell(inner, title="Log in to continue | Insureon")