Download tasks/insureon/solution/site/implementation/clone/views/account.py from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 21.1 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/insureon/solution/site/implementation/clone/views/account.py
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/insureon/solution/site/implementation/clone/views/account.py
-
curl -L -o account.py https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/insureon/solution/site/implementation/clone/views/account.py
21.1 kB
| """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 = ( | |
| '<a href="/legal/terms-of-use">Terms of use</a> and ' | |
| '<a href="/legal/privacy-policy">Privacy policy</a>' | |
| ) | |
| def _auth_shell(inner: str, *, title: str, description: str = "") -> str: | |
| body = f"""<section class="section" style="padding:3.5rem 0 5rem"> | |
| <div class="wrap">{inner}</div> | |
| </section>""" | |
| return R.page(body, title=title, description=description) | |
| def _account_shell(inner: str, *, title: str, active: str, | |
| account_name: str = "") -> str: | |
| nav = "".join( | |
| '<a href="{}"{}>{}</a>'.format( | |
| href, ' class="is-active"' if href == active else "", R.esc(label)) | |
| for href, label in ACCOUNT_NAV | |
| ) | |
| body = f"""<section class="page-head" style="padding:2.25rem 0 1.75rem"> | |
| <div class="wrap"> | |
| <h1 style="font-size:1.9rem">My account</h1> | |
| <p style="color:var(--ion-muted);margin:0">{R.esc(account_name)}</p> | |
| </div> | |
| </section> | |
| <section class="section" style="padding-top:2rem"> | |
| <div class="wrap"><div class="acct-nav">{nav}</div>{inner}</div> | |
| </section>""" | |
| 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"""<div class="form-card" style="max-width:30rem"> | |
| <h1 style="font-size:1.6rem;text-align:center">Log in to your account</h1> | |
| <p style="text-align:center;color:var(--ion-muted)"> | |
| Manage your policies, quotes and certificates of insurance.</p> | |
| {R.notice(notice)} | |
| {R.error_summary(errors)} | |
| <form method="post" action="/account/login"> | |
| <input type="hidden" name="next" value="{R.esc(next_url)}"> | |
| {R.field("email", "Email address", kind="email", value=email, | |
| error=errors.get("email", ""), required=True, | |
| attrs='autocomplete="email"')} | |
| {R.field("password", "Password", kind="password", | |
| error=errors.get("password", ""), required=True, | |
| attrs='autocomplete="current-password"')} | |
| <button class="btn btn--primary btn--block" type="submit">Log in</button> | |
| </form> | |
| <p style="text-align:center;margin-top:1.25rem"> | |
| <a href="/account/forgot-password">Forgot your password?</a></p> | |
| <p style="text-align:center;color:var(--ion-muted);font-size:.9rem"> | |
| Don't have an account? <a href="/account/register">Create one</a></p> | |
| <p style="text-align:center;color:var(--ion-muted);font-size:.8rem;margin-top:1.5rem"> | |
| This offline demonstration site issues its own local credentials. It does not | |
| use, accept or forward any real Insureon account.</p> | |
| </div>""" | |
| 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"""<div class="form-card" style="max-width:30rem"> | |
| <h1 style="font-size:1.6rem;text-align:center">Confirm your email</h1> | |
| <p style="color:var(--ion-muted)">We sent a 6-digit confirmation code to | |
| <strong>{R.esc(email)}</strong>. Enter it below to finish creating your account.</p> | |
| {R.notice(code_hint)} | |
| {R.error_summary(errors)} | |
| <form method="post" action="/account/register"> | |
| <input type="hidden" name="stage" value="verify"> | |
| <input type="hidden" name="next" value="{R.esc(next_url)}"> | |
| {R.field("code", "Confirmation code", value="", error=errors.get("code", ""), | |
| required=True, attrs='inputmode="numeric" maxlength="6" autocomplete="one-time-code"')} | |
| <button class="btn btn--primary btn--block" type="submit">Create my account</button> | |
| </form> | |
| <p style="text-align:center;margin-top:1.25rem"> | |
| <a href="/account/register">Start over</a> · | |
| <a href="/account/login">Back to log in</a></p> | |
| </div>""" | |
| return _auth_shell(inner, title="Confirm your email | Insureon") | |
| inner = f"""<div class="form-card" style="max-width:32rem"> | |
| <h1 style="font-size:1.6rem;text-align:center">Create your account</h1> | |
| <p style="text-align:center;color:var(--ion-muted)"> | |
| Save your quotes, download certificates and manage policies in one place.</p> | |
| {R.error_summary(errors)} | |
| <form method="post" action="/account/register"> | |
| <input type="hidden" name="stage" value="details"> | |
| <input type="hidden" name="next" value="{R.esc(next_url)}"> | |
| {R.field("name", "Full name", value=values.get("name", ""), | |
| error=errors.get("name", ""), required=True, attrs='autocomplete="name"')} | |
| {R.field("email", "Email address", kind="email", value=values.get("email", ""), | |
| error=errors.get("email", ""), required=True, | |
| hint="We send policy documents and confirmation codes to this address.", | |
| attrs='autocomplete="email"')} | |
| {R.field("password", "Password", kind="password", | |
| error=errors.get("password", ""), required=True, | |
| hint="At least 12 characters.", attrs='autocomplete="new-password"')} | |
| <p style="font-size:.85rem;color:var(--ion-muted)"> | |
| We will email you a 6-digit confirmation code to verify this address before | |
| your account is created.</p> | |
| <p style="font-size:.85rem;color:var(--ion-muted)"> | |
| By creating an account you agree to our {TERMS_LINKS}.</p> | |
| <button class="btn btn--primary btn--block" type="submit">Continue</button> | |
| </form> | |
| <p style="text-align:center;color:var(--ion-muted);font-size:.9rem;margin-top:1.25rem"> | |
| Already have an account? <a href="/account/login">Log in</a></p> | |
| </div>""" | |
| 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 = ('<p style="text-align:center;margin-top:1.25rem">' | |
| '<a href="/account/login">Return to log in</a></p>') | |
| if stage == "verify": | |
| inner = f"""<div class="form-card" style="max-width:30rem"> | |
| <h1 style="font-size:1.6rem;text-align:center">Enter your reset code</h1> | |
| <p style="color:var(--ion-muted)">If an account exists for | |
| <strong>{R.esc(email)}</strong>, we sent it a 6-digit reset code.</p> | |
| {R.notice(code_hint)} | |
| {R.error_summary(errors)} | |
| <form method="post" action="/account/forgot-password"> | |
| <input type="hidden" name="stage" value="verify"> | |
| {R.field("code", "Reset code", error=errors.get("code", ""), required=True, | |
| attrs='inputmode="numeric" maxlength="6" autocomplete="one-time-code"')} | |
| {R.field("new_password", "New password", kind="password", | |
| error=errors.get("new_password", ""), required=True, | |
| hint="At least 12 characters.", attrs='autocomplete="new-password"')} | |
| <button class="btn btn--primary btn--block" type="submit">Set new password</button> | |
| </form>{back}</div>""" | |
| return _auth_shell(inner, title="Reset your password | Insureon") | |
| inner = f"""<div class="form-card" style="max-width:30rem"> | |
| <h1 style="font-size:1.6rem;text-align:center">Reset your password</h1> | |
| <p style="color:var(--ion-muted)">Enter the email address on your account and we | |
| will send a 6-digit reset code to it.</p> | |
| {R.notice(notice)} | |
| {R.error_summary(errors)} | |
| <form method="post" action="/account/forgot-password"> | |
| <input type="hidden" name="stage" value="request"> | |
| {R.field("email", "Email address on your account", kind="email", value=email, | |
| error=errors.get("email", ""), required=True, | |
| hint="Enter the address exactly as you registered it.", | |
| attrs='autocomplete="email"')} | |
| <button class="btn btn--primary btn--block" type="submit">Send reset code</button> | |
| </form> | |
| <p style="font-size:.82rem;color:var(--ion-muted);margin-top:1rem"> | |
| For your security we show the same confirmation whether or not an account | |
| exists for the address you enter.</p>{back}</div>""" | |
| 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'<a class="btn btn--ghost btn--sm" href="{R.esc(href)}">{R.esc(label)}</a>' | |
| for label, href in actions | |
| ) | |
| return f"""<div class="record{' record--newest' if newest else ''}"> | |
| <div> | |
| <div class="record__title">{R.esc(title)} | |
| {R.badge(status) if status else ''}</div> | |
| <div class="record__meta">{R.esc(meta)}</div> | |
| </div> | |
| <div class="record__actions">{acts}</div> | |
| </div>""" | |
| def overview(account_name: str, applications: Sequence[Mapping[str, Any]], | |
| policies: Sequence[Mapping[str, Any]], | |
| documents: Sequence[Mapping[str, Any]]) -> str: | |
| tiles = f"""<div class="tile-grid" style="margin-bottom:2rem"> | |
| <div class="tile"><h3>{len(applications)}</h3><p>Quote applications</p> | |
| <a href="/account/quotes">View saved quotes</a></div> | |
| <div class="tile"><h3>{len(policies)}</h3><p>Policies</p> | |
| <a href="/account/policies">Manage policies</a></div> | |
| <div class="tile"><h3>{len(documents)}</h3><p>Documents</p> | |
| <a href="/account/documents">View documents</a></div> | |
| </div>""" | |
| 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 '<div class="empty-state">You have no quote applications yet. ' \ | |
| '<a href="/start-quote">Start a quote</a>.</div>' | |
| inner = (tiles + "<h2 style='font-size:1.3rem'>Recent activity</h2>" | |
| + f'<div class="record-list">{recent}</div>') | |
| 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 ('<div class="empty-state">You have not saved any quotes yet. ' | |
| '<a href="/start-quote">Start a quote</a> and save it to come back to it.</div>') | |
| inner = (R.notice(notice) | |
| + "<h2 style='font-size:1.3rem'>Saved quotes</h2>" | |
| + "<p style='color:var(--ion-muted)'>Open a saved quote to change an " | |
| "input and recalculate your options.</p>" | |
| + f'<div class="record-list">{rows}</div>') | |
| 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 ('<div class="empty-state">You have no policies yet. ' | |
| '<a href="/start-quote">Get quotes</a> to buy coverage.</div>') | |
| inner = (R.notice(notice) + "<h2 style='font-size:1.3rem'>Your policies</h2>" | |
| + f'<div class="record-list">{items}</div>') | |
| 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'<li><a href="/account/documents/{R.esc(d["id"])}">{R.esc(d["title"])}</a>' | |
| f' <span style="color:var(--ion-muted);font-size:.82rem">' | |
| f'({R.esc(str(d.get("issued_at", ""))[:10])})</span></li>' | |
| for d in documents | |
| ) or "<li>No documents issued for this policy yet.</li>" | |
| active = str(p.get("status")) == "active" | |
| cancel = f"""<form method="post" action="/account/policies/{R.esc(p['id'])}/cancel" | |
| onsubmit="return confirm('Cancel policy {R.esc(p['number'])}? This cannot be undone.')"> | |
| <button class="btn btn--ghost btn--sm" type="submit" | |
| style="border-color:#c62828;color:#c62828">Cancel this policy</button> | |
| </form>""" if active else "" | |
| coi = f"""<form method="post" action="/account/policies/{R.esc(p['id'])}/certificate"> | |
| <div class="field-row" style="align-items:end"> | |
| {R.field("holder_name", "Certificate holder", | |
| placeholder="Lakeside Property Group", | |
| hint="The client or landlord who needs proof of your coverage.")} | |
| <div class="field"><button class="btn btn--primary btn--block" type="submit"> | |
| Issue certificate of insurance</button></div> | |
| </div> | |
| </form>""" if active else "" | |
| inner = f"""{R.notice(notice)} | |
| <a href="/account/policies" style="font-size:.85rem">← Back to policies</a> | |
| <h2 style="font-size:1.4rem;margin-top:1rem">{R.esc(p["product_name"])} — | |
| {R.esc(p["carrier_name"])} {R.badge(str(p.get("status", "")))}</h2> | |
| <div class="two-col" style="align-items:start;margin-top:1.5rem"> | |
| <div> | |
| <table class="summary-table"> | |
| <tr><th>Policy number</th><td>{R.esc(p["number"])}</td></tr> | |
| <tr><th>Carrier</th><td>{R.esc(p["carrier_name"])}</td></tr> | |
| <tr><th>Status</th><td>{R.esc(str(p.get("status", "")).title())}</td></tr> | |
| <tr><th>Effective date</th><td>{R.esc(p["effective_date"])}</td></tr> | |
| <tr><th>Expiration date</th><td>{R.esc(p["expiration_date"])}</td></tr> | |
| <tr class="total"><th>Annual premium</th> | |
| <td>{R.money(p["annual_premium_cents"])}</td></tr> | |
| </table> | |
| <div style="margin-top:1.5rem;display:flex;gap:.75rem;flex-wrap:wrap"> | |
| <a class="btn btn--ghost btn--sm" href="/account/profile">Billing details</a> | |
| <a class="btn btn--ghost btn--sm" href="/claims">File a claim</a> | |
| <a class="btn btn--ghost btn--sm" href="/contact-us">Contact support</a> | |
| {cancel} | |
| </div> | |
| </div> | |
| <div> | |
| <h3>Documents</h3> | |
| <ul class="prose">{docs}</ul> | |
| {coi} | |
| </div> | |
| </div>""" | |
| 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 ('<div class="empty-state">No documents yet. Documents are issued when you ' | |
| 'get quotes and when you buy a policy.</div>') | |
| inner = ("<h2 style='font-size:1.3rem'>Your documents</h2>" | |
| + f'<div class="record-list">{items}</div>') | |
| 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"""<a href="/account/documents" style="font-size:.85rem">← Back to documents</a> | |
| <h2 style="font-size:1.4rem;margin-top:1rem">{R.esc(d["title"])}</h2> | |
| <p style="color:var(--ion-muted)"> | |
| {R.esc(str(d.get("kind", "")).replace("-", " ").title())} · | |
| issued {R.esc(str(d.get("issued_at", ""))[:10])}</p> | |
| <div class="doc-body">{R.esc(d.get("body", ""))}</div>""" | |
| 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'<tr><th>{R.esc(str(p.get("created_at", ""))[:10])}</th>' | |
| f'<td>{R.money(p["amount_cents"])} · {R.esc(p.get("method_label", ""))} · ' | |
| f'{R.esc(str(p.get("status", "")).title())}</td></tr>' | |
| for p in payments | |
| ) or '<tr><td colspan="2">No payments recorded.</td></tr>' | |
| inner = f"""{R.notice(notice)} | |
| <div class="two-col" style="align-items:start"> | |
| <div> | |
| <h2 style="font-size:1.3rem">Profile</h2> | |
| <form method="post" action="/account/profile"> | |
| {R.field("display_name", "Name on account", value=account_name)} | |
| {R.field("email", "Email address", kind="email", value=email, | |
| attrs='readonly aria-readonly="true"', | |
| hint="Contact support to change the email on your account.")} | |
| <button class="btn btn--primary" type="submit">Save changes</button> | |
| </form> | |
| </div> | |
| <div> | |
| <h2 style="font-size:1.3rem">Billing history</h2> | |
| <table class="summary-table">{rows}</table> | |
| <p style="font-size:.82rem;color:var(--ion-muted);margin-top:1rem"> | |
| This offline demonstration site records local sandbox payments only. No card | |
| details are collected, stored or transmitted.</p> | |
| </div> | |
| </div>""" | |
| 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"""<div class="form-card" style="max-width:32rem;text-align:center"> | |
| <h1 style="font-size:1.5rem">Log in to continue</h1> | |
| <p style="color:var(--ion-muted)">You need to be logged in to view {R.esc(what)}. | |
| Your quote is saved and you can pick up where you left off.</p> | |
| <div class="btn-row"> | |
| <a class="btn btn--primary" href="/account/login?next={R.esc(next_url)}">Log in</a> | |
| <a class="btn btn--ghost" href="/account/register?next={R.esc(next_url)}">Create an account</a> | |
| </div> | |
| </div>""" | |
| return _auth_shell(inner, title="Log in to continue | Insureon") | |