|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
// CRATES
|
|
|
|
|
use crate::utils::{prefs, template, Preferences}; |
|
|
|
|
use crate::utils::{prefs, redirect, template, Preferences}; |
|
|
|
|
use askama::Template; |
|
|
|
|
use tide::{http::Cookie, Request, Response}; |
|
|
|
|
use tide::{http::Cookie, Request}; |
|
|
|
|
use time::{Duration, OffsetDateTime}; |
|
|
|
|
|
|
|
|
|
// STRUCTS
|
|
|
|
@ -35,11 +35,7 @@ pub async fn get(req: Request<()>) -> tide::Result { |
|
|
|
|
pub async fn set(mut req: Request<()>) -> tide::Result { |
|
|
|
|
let form: SettingsForm = req.body_form().await.unwrap_or_default(); |
|
|
|
|
|
|
|
|
|
let mut res = Response::builder(302) |
|
|
|
|
.content_type("text/html") |
|
|
|
|
.header("Location", "/settings") |
|
|
|
|
.body(r#"Redirecting to <a href="/settings">settings</a>..."#) |
|
|
|
|
.build(); |
|
|
|
|
let mut res = redirect("/settings".to_string()); |
|
|
|
|
|
|
|
|
|
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "show_nsfw"]; |
|
|
|
|
let values = vec![form.theme, form.front_page, form.layout, form.wide, form.comment_sort, form.show_nsfw]; |
|
|
|
@ -60,22 +56,16 @@ pub async fn set(mut req: Request<()>) -> tide::Result { |
|
|
|
|
Ok(res) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set cookies using response "Set-Cookie" header
|
|
|
|
|
pub async fn restore(req: Request<()>) -> tide::Result { |
|
|
|
|
let form: SettingsForm = req.query()?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let path = match form.redirect { |
|
|
|
|
Some(value) => format!("/{}/", value), |
|
|
|
|
None => "/".to_string() |
|
|
|
|
None => "/".to_string(), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let mut res = Response::builder(302) |
|
|
|
|
.content_type("text/html") |
|
|
|
|
.header("Location", path.to_owned()) |
|
|
|
|
.body(format!("Redirecting to <a href=\"{0}\">{0}</a>...", path)) |
|
|
|
|
.build(); |
|
|
|
|
let mut res = redirect(path); |
|
|
|
|
|
|
|
|
|
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "show_nsfw", "subscriptions"]; |
|
|
|
|
let values = vec![form.theme, form.front_page, form.layout, form.wide, form.comment_sort, form.show_nsfw, form.subscriptions]; |
|
|
|
|