Skip to main content

codoseo_web/routes/
landing.rs

1//! The cloud landing page at `/`: one URL box that starts a no-signup audit.
2
3use askama::Template;
4use axum::http::StatusCode;
5use axum::response::{IntoResponse, Response};
6
7use crate::error::AppError;
8use crate::render::html;
9use crate::state::AppState;
10
11#[derive(Template)]
12#[template(path = "landing/index.html")]
13pub struct Landing {
14    /// What the visitor typed, kept when the address is refused.
15    pub url: String,
16    pub error: Option<String>,
17    pub checks: usize,
18    pub base: String,
19    /// Set when Turnstile is configured: the widget and its script are shown.
20    pub turnstile_site_key: Option<String>,
21}
22
23fn view(state: &AppState, url: &str, error: Option<String>) -> Landing {
24    Landing {
25        url: url.to_owned(),
26        error,
27        checks: codoseo_checks::CHECKS.len(),
28        base: state.config.origin(),
29        turnstile_site_key: state.config.turnstile.as_ref().map(|t| t.site_key.clone()),
30    }
31}
32
33/// The landing page for a signed-out visitor.
34pub fn page(state: &AppState) -> Result<Response, AppError> {
35    Ok(html(&view(state, "", None))?.into_response())
36}
37
38/// The landing page again with a message under the box, for a submit we turned away.
39pub fn refuse(
40    state: &AppState,
41    url: &str,
42    status: StatusCode,
43    message: String,
44) -> Result<Response, AppError> {
45    Ok((status, html(&view(state, url.trim(), Some(message)))?).into_response())
46}