2018-06-18 17:59:49 +02:00
|
|
|
use rocket_contrib::Template;
|
2018-06-21 11:58:54 +02:00
|
|
|
use rocket::Request;
|
|
|
|
use rocket::request::FromRequest;
|
2018-09-03 15:59:02 +02:00
|
|
|
use plume_models::db_conn::DbConn;
|
2018-06-23 18:36:11 +02:00
|
|
|
use plume_models::users::User;
|
2018-06-18 17:59:49 +02:00
|
|
|
|
|
|
|
#[catch(404)]
|
2018-06-21 11:58:54 +02:00
|
|
|
fn not_found(req: &Request) -> Template {
|
2018-10-20 11:04:20 +02:00
|
|
|
let conn = req.guard::<DbConn>().succeeded();
|
2018-06-21 11:58:54 +02:00
|
|
|
let user = User::from_request(req).succeeded();
|
2018-06-18 17:59:49 +02:00
|
|
|
Template::render("errors/404", json!({
|
2018-06-21 11:58:54 +02:00
|
|
|
"error_message": "Page not found",
|
2018-10-20 11:04:20 +02:00
|
|
|
"account": user.and_then(|u| conn.map(|conn| u.to_json(&*conn)))
|
2018-06-18 17:59:49 +02:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[catch(500)]
|
2018-06-21 11:58:54 +02:00
|
|
|
fn server_error(req: &Request) -> Template {
|
2018-10-20 11:04:20 +02:00
|
|
|
let conn = req.guard::<DbConn>().succeeded();
|
2018-06-21 11:58:54 +02:00
|
|
|
let user = User::from_request(req).succeeded();
|
2018-06-18 17:59:49 +02:00
|
|
|
Template::render("errors/500", json!({
|
2018-06-21 11:58:54 +02:00
|
|
|
"error_message": "Server error",
|
2018-10-20 11:04:20 +02:00
|
|
|
"account": user.and_then(|u| conn.map(|conn| u.to_json(&*conn)))
|
2018-06-18 17:59:49 +02:00
|
|
|
}))
|
|
|
|
}
|
2018-06-24 18:58:57 +02:00
|
|
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
pub struct Uri {
|
|
|
|
target: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/csrf-violation?<uri>")]
|
|
|
|
fn csrf_violation(uri: Option<Uri>) -> Template {
|
|
|
|
if let Some(uri) = uri {
|
|
|
|
eprintln!("Csrf violation while acceding \"{}\"", uri.target)
|
|
|
|
}
|
|
|
|
Template::render("errors/csrf", json!({
|
|
|
|
"error_message":""
|
|
|
|
}))
|
|
|
|
}
|