diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/form/Cargo.toml (renamed from examples/csrf/Cargo.toml) | 2 | ||||
| -rw-r--r-- | examples/form/src/main.rs (renamed from examples/csrf/src/main.rs) | 19 | 
2 files changed, 9 insertions, 12 deletions
diff --git a/examples/csrf/Cargo.toml b/examples/form/Cargo.toml index b6768ed..6f899df 100644 --- a/examples/csrf/Cargo.toml +++ b/examples/form/Cargo.toml @@ -1,5 +1,5 @@  [package] -name = "csrf" +name = "sputnik-demo"  version = "0.1.0"  authors = ["Martin Fischer <martin@push-f.com>"]  edition = "2018" diff --git a/examples/csrf/src/main.rs b/examples/form/src/main.rs index 53ea87f..e354f9f 100644 --- a/examples/csrf/src/main.rs +++ b/examples/form/src/main.rs @@ -4,8 +4,8 @@ use hyper::{Method, Server, StatusCode, Body};  use hyper::http::request::Parts;  use hyper::http::response::Builder;  use serde::Deserialize; -use sputnik::{mime, request::{SputnikParts, SputnikBody, CsrfToken}, response::SputnikBuilder}; -use sputnik::request::CsrfProtectedFormError; +use sputnik::{mime, request::{SputnikParts, SputnikBody}, response::SputnikBuilder}; +use sputnik::request::FormError;  type Response = hyper::Response<Body>; @@ -14,13 +14,13 @@ enum Error {      #[error("page not found")]      NotFound(String),      #[error("{0}")] -    CsrfError(#[from] CsrfProtectedFormError) +    FormError(#[from] FormError)  }  fn render_error(err: Error) -> (StatusCode, String) {      match err {          Error::NotFound(msg) => (StatusCode::NOT_FOUND, msg), -        Error::CsrfError(err) => (StatusCode::BAD_REQUEST, err.to_string()), +        Error::FormError(err) => (StatusCode::BAD_REQUEST, err.to_string()),      }  } @@ -32,22 +32,19 @@ async fn route(req: &mut Parts, body: Body) -> Result<Response, Error> {      }  } -fn get_form(req: &mut Parts) -> Response { +fn get_form(_req: &mut Parts) -> Response {      Builder::new()      .content_type(mime::TEXT_HTML)      .body( -        format!( -            "<form method=post><input name=text>{}<button>Submit</button></form>", -            CsrfToken::from_request(req).html_input() -        ).into() +        "<form method=post><input name=text> <button>Submit</button></form>".into()      ).unwrap()  }  #[derive(Deserialize)]  struct FormData {text: String} -async fn post_form(req: &mut Parts, body: Body) -> Result<Response, Error> { -    let msg: FormData = body.into_form_csrf(req).await?; +async fn post_form(_req: &mut Parts, body: Body) -> Result<Response, Error> { +    let msg: FormData = body.into_form().await?;      Ok(Builder::new().body(          format!("hello {}", msg.text).into()      ).unwrap())  | 
