use topcoat::{ Result, context::Cx, cookie::{Cookies, cookies}, router::{ content::Form, error::{SeeOther, bad_request, see_other}, route, }, }; use super::lang::safe_back; use crate::scheme::{Scheme, scheme_cookie}; #[derive(serde::Deserialize)] struct SchemeForm { scheme: String, /// Where to return to. Only a relative path on this site is accepted. #[serde(default)] back: String, } /// POST /scheme: stores the chosen color scheme in a cookie and returns to the page it /// was chosen on. #[route(POST)] async fn set_scheme(cx: &Cx, Form(form): Form) -> Result { let scheme = Scheme::from_id(form.scheme.trim()) .ok_or_else(|| bad_request("unsupported color scheme"))?; cookies(cx).add(scheme_cookie(scheme)); Ok(see_other(safe_back(&form.back))) }