July 3rd - Update landing page
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
app/routes/landing.py
|
||||
----------------------
|
||||
Public marketing / landing page served at the apex domain (e.g. jqc.app).
|
||||
|
||||
Canonical path is GET /welcome (always reachable, tenant-exempt) so the page
|
||||
can be previewed directly in any environment. In multi-tenant production the
|
||||
tenant middleware delegates the apex host's `/` to this view (see
|
||||
app/tenancy/middleware.py) — the apex is NOT a tenant, so `/` cannot be owned
|
||||
by the login-gated dashboard route.
|
||||
|
||||
The page introduces the product, lists plans (read live from the control DB
|
||||
when available, with a static fallback), and funnels visitors to the existing
|
||||
public self-service signup at /signup (plan picker, Free selectable/default).
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from flask import Blueprint, render_template, current_app, url_for
|
||||
|
||||
bp = Blueprint('landing', __name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Static fallback mirrors control/seed.py PLAN_DEFS so the page still renders if
|
||||
# the control DB is unreachable or multi-tenancy is disabled (dev preview).
|
||||
_FALLBACK_PLANS = [
|
||||
dict(code='free', name='Free', price_label='$0',
|
||||
max_users=3, max_facilities=2, max_inspections_month=50, max_issues_month=50,
|
||||
allow_mobile_api=False, allow_scheduled_reports=False,
|
||||
allow_branding=False, allow_custom_domain=False),
|
||||
dict(code='starter', name='Starter', price_label='Contact us',
|
||||
max_users=15, max_facilities=10, max_inspections_month=500, max_issues_month=500,
|
||||
allow_mobile_api=True, allow_scheduled_reports=False,
|
||||
allow_branding=False, allow_custom_domain=False),
|
||||
dict(code='pro', name='Pro', price_label='Contact us',
|
||||
max_users=50, max_facilities=50, max_inspections_month=5000, max_issues_month=5000,
|
||||
allow_mobile_api=True, allow_scheduled_reports=True,
|
||||
allow_branding=True, allow_custom_domain=True),
|
||||
dict(code='enterprise', name='Enterprise', price_label='Contact us',
|
||||
max_users=None, max_facilities=None, max_inspections_month=None, max_issues_month=None,
|
||||
allow_mobile_api=True, allow_scheduled_reports=True,
|
||||
allow_branding=True, allow_custom_domain=True),
|
||||
]
|
||||
|
||||
|
||||
def _plan_dict(p):
|
||||
"""Flatten a control Plan ORM row into a template-safe dict (read inside the
|
||||
open session so no lazy attribute access happens after it closes)."""
|
||||
if p.price_cents == 0:
|
||||
price_label = '$0'
|
||||
elif p.price_cents:
|
||||
price_label = f'${p.price_cents // 100}/mo'
|
||||
else:
|
||||
price_label = 'Contact us'
|
||||
return dict(
|
||||
code=p.code, name=p.name, price_label=price_label,
|
||||
max_users=p.max_users, max_facilities=p.max_facilities,
|
||||
max_inspections_month=p.max_inspections_month,
|
||||
max_issues_month=p.max_issues_month,
|
||||
allow_mobile_api=p.allow_mobile_api,
|
||||
allow_scheduled_reports=p.allow_scheduled_reports,
|
||||
allow_branding=p.allow_branding,
|
||||
allow_custom_domain=p.allow_custom_domain,
|
||||
)
|
||||
|
||||
|
||||
def _load_plans():
|
||||
"""Return plan dicts from the control DB, ordered cheapest-first, with a
|
||||
static fallback so the landing page never fails to render."""
|
||||
try:
|
||||
from control.base import control_session
|
||||
from control.models import Plan
|
||||
with control_session() as s:
|
||||
plans = (s.query(Plan)
|
||||
.order_by(Plan.price_cents.nullslast(), Plan.id)
|
||||
.all())
|
||||
if plans:
|
||||
return [_plan_dict(p) for p in plans]
|
||||
except Exception as exc:
|
||||
logger.debug('LANDING | plan_load_failed | err=%s', exc)
|
||||
return _FALLBACK_PLANS
|
||||
|
||||
|
||||
@bp.route('/welcome')
|
||||
def index():
|
||||
return render_template(
|
||||
'landing/index.html',
|
||||
plans=_load_plans(),
|
||||
signup_url=url_for('signup.index'),
|
||||
base_domain=current_app.config.get('TENANT_BASE_DOMAIN', 'jqc.app'),
|
||||
)
|
||||
+20
-3
@@ -27,16 +27,28 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _send_welcome_email(to_email, login_url, tenant_name, plan_code, trial_ends_at):
|
||||
"""Fire a welcome email in a background thread — never blocks the request."""
|
||||
"""Fire a welcome email in a background thread — never blocks the request.
|
||||
|
||||
The wording adapts to the plan: the Free plan has no trial/expiry, paid
|
||||
plans start a 14-day trial. `trial_note` carries the plan-appropriate line
|
||||
and `trial_ends_at` is blank for Free so the template hides the trial row.
|
||||
"""
|
||||
try:
|
||||
from app.billing.emails import send_billing_email
|
||||
is_free = (plan_code == 'free')
|
||||
ends_str = (trial_ends_at.strftime('%B %d, %Y')
|
||||
if hasattr(trial_ends_at, 'strftime') else str(trial_ends_at or ''))
|
||||
if is_free:
|
||||
trial_note = "You're on the Free plan — no credit card, no expiry."
|
||||
ends_str = ''
|
||||
else:
|
||||
trial_note = f'Your 14-day free trial runs through {ends_str}.'
|
||||
send_billing_email(to_email, 'welcome', {
|
||||
'tenant_name': tenant_name,
|
||||
'login_url': login_url,
|
||||
'trial_days': 14,
|
||||
'trial_days': 0 if is_free else 14,
|
||||
'trial_ends_at': ends_str,
|
||||
'trial_note': trial_note,
|
||||
'plan_name': plan_code.title(),
|
||||
})
|
||||
except Exception as exc:
|
||||
@@ -115,6 +127,11 @@ def index():
|
||||
plan_code = form.plan.data
|
||||
password = form.password.data
|
||||
|
||||
# Free plan is free forever — no trial, no expiry. Paid plans start a
|
||||
# 14-day trial. trial_days=0 makes create_tenant provision the tenant as
|
||||
# 'active' (see control/provision.py) so the billing gate never blocks it.
|
||||
trial_days = 0 if plan_code == 'free' else 14
|
||||
|
||||
try:
|
||||
from control.provision import create_tenant
|
||||
info = create_tenant(
|
||||
@@ -124,7 +141,7 @@ def index():
|
||||
admin_email=email,
|
||||
admin_full_name=full_name,
|
||||
admin_password=password,
|
||||
trial_days=14,
|
||||
trial_days=trial_days,
|
||||
)
|
||||
except ValueError as exc:
|
||||
flash(str(exc), 'danger')
|
||||
|
||||
Reference in New Issue
Block a user