2018-06-21 11:58:54 +02:00
|
|
|
use rocket::Request;
|
|
|
|
use rocket::request::FromRequest;
|
2018-12-06 18:54:16 +01:00
|
|
|
use rocket_i18n::I18n;
|
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-12-06 18:54:16 +01:00
|
|
|
use template_utils::Ructe;
|
2018-06-18 17:59:49 +02:00
|
|
|
|
|
|
|
#[catch(404)]
|
2018-12-06 18:54:16 +01:00
|
|
|
pub fn not_found(req: &Request) -> Ructe {
|
2018-10-20 11:04:20 +02:00
|
|
|
let conn = req.guard::<DbConn>().succeeded();
|
2018-12-06 18:54:16 +01:00
|
|
|
let intl = req.guard::<I18n>().succeeded();
|
2018-06-21 11:58:54 +02:00
|
|
|
let user = User::from_request(req).succeeded();
|
2018-12-06 18:54:16 +01:00
|
|
|
render!(errors::not_found(
|
|
|
|
&(&*conn.unwrap(), &intl.unwrap().catalog, user)
|
|
|
|
))
|
2018-06-18 17:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[catch(500)]
|
2018-12-06 18:54:16 +01:00
|
|
|
pub fn server_error(req: &Request) -> Ructe {
|
2018-10-20 11:04:20 +02:00
|
|
|
let conn = req.guard::<DbConn>().succeeded();
|
2018-12-06 18:54:16 +01:00
|
|
|
let intl = req.guard::<I18n>().succeeded();
|
2018-06-21 11:58:54 +02:00
|
|
|
let user = User::from_request(req).succeeded();
|
2018-12-06 18:54:16 +01:00
|
|
|
render!(errors::server_error(
|
|
|
|
&(&*conn.unwrap(), &intl.unwrap().catalog, user)
|
|
|
|
))
|
2018-06-18 17:59:49 +02:00
|
|
|
}
|
2018-06-24 18:58:57 +02:00
|
|
|
|
2018-12-06 18:54:16 +01:00
|
|
|
#[post("/csrf-violation?<target>")]
|
|
|
|
pub fn csrf_violation(target: Option<String>, conn: DbConn, intl: I18n, user: Option<User>) -> Ructe {
|
|
|
|
if let Some(uri) = target {
|
|
|
|
eprintln!("Csrf violation while acceding \"{}\"", uri)
|
2018-06-24 18:58:57 +02:00
|
|
|
}
|
2018-12-06 18:54:16 +01:00
|
|
|
render!(errors::csrf(
|
|
|
|
&(&*conn, &intl.catalog, user)
|
|
|
|
))
|
2018-06-24 18:58:57 +02:00
|
|
|
}
|