| 1 | use topcoat::{ |
| 2 | Result, |
| 3 | context::Cx, |
| 4 | cookie::{Cookies, cookies}, |
| 5 | router::{ |
| 6 | content::Form, |
| 7 | error::{SeeOther, bad_request, see_other}, |
| 8 | route, |
| 9 | }, |
| 10 | }; |
| 11 | |
| 12 | use super::lang::safe_back; |
| 13 | use crate::scheme::{Scheme, scheme_cookie}; |
| 14 | |
| 15 | #[derive(serde::Deserialize)] |
| 16 | struct SchemeForm { |
| 17 | scheme: String, |
| 18 | |
| 19 | #[serde(default)] |
| 20 | back: String, |
| 21 | } |
| 22 | |
| 23 | |
| 24 | |
| 25 | #[route(POST)] |
| 26 | async fn set_scheme(cx: &Cx, Form(form): Form<SchemeForm>) -> Result<SeeOther> { |
| 27 | let scheme = Scheme::from_id(form.scheme.trim()) |
| 28 | .ok_or_else(|| bad_request("unsupported color scheme"))?; |
| 29 | cookies(cx).add(scheme_cookie(scheme)); |
| 30 | Ok(see_other(safe_back(&form.back))) |
| 31 | } |