From 55b9883a5423d01702e8f45189947f355a62b7cb Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 17 Oct 2020 05:14:03 +0500 Subject: [PATCH] Rename vars --- README.md | 14 +++++++------- examples/minimal/src/main.rs | 10 +++++----- examples/minimal/templates/comments/new.html.hbs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2f9713e..c66ce55 100644 --- a/README.md +++ b/README.md @@ -53,12 +53,12 @@ use rocket_contrib::templates::Template; use rocket_csrf::CsrfToken; #[get("/comments/new")] -fn new(csrf: CsrfToken) -> Template { +fn new(csrf_token: CsrfToken) -> Template { // your code } #[post("/comments", data = "
")] -fn create(csrf: CsrfToken, form: Form) -> Redirect { +fn create(csrf_token: CsrfToken, form: Form) -> Redirect { // your code } ``` @@ -69,8 +69,8 @@ to use it in [templates](https://rocket.rs/v0.4/guide/responses/#templates): ```rust #[get("/comments/new")] -fn new(csrf: CsrfToken) -> Template { - let csrf_token: String = csrf.0; +fn new(csrf_token: CsrfToken) -> Template { + let authenticity_token: String = csrf_token.0; // your code } @@ -81,7 +81,7 @@ Add CSRF token to your HTML forms in ```html - + ``` @@ -102,8 +102,8 @@ authenticity token: ```rust #[post("/comments", data = "
")] -fn create(csrf: CsrfToken, form: Form) -> Redirect { - if let Err(_) = csrf.verify(&form.authenticity_token) { +fn create(csrf_token: CsrfToken, form: Form) -> Redirect { + if let Err(_) = csrf_token.verify(&form.authenticity_token) { return Redirect::to(uri!(new)); } diff --git a/examples/minimal/src/main.rs b/examples/minimal/src/main.rs index 2d3cb5e..de8e578 100644 --- a/examples/minimal/src/main.rs +++ b/examples/minimal/src/main.rs @@ -10,7 +10,7 @@ use rocket_csrf::CsrfToken; #[derive(Serialize)] struct TemplateContext { - csrf_token: String, + authenticity_token: String, flash: Option, } @@ -34,9 +34,9 @@ fn index() -> Redirect { } #[get("/comments/new")] -fn new(csrf: CsrfToken, flash: Option) -> Template { +fn new(csrf_token: CsrfToken, flash: Option) -> Template { let template_context = TemplateContext { - csrf_token: csrf.0, + authenticity_token: csrf_token.0, flash: flash.map(|msg| format!("{}! {}", msg.name(), msg.msg())), }; @@ -44,8 +44,8 @@ fn new(csrf: CsrfToken, flash: Option) -> Template { } #[post("/comments", data = "")] -fn create(csrf: CsrfToken, form: Form) -> Flash { - if let Err(_) = csrf.verify(&form.authenticity_token) { +fn create(csrf_token: CsrfToken, form: Form) -> Flash { + if let Err(_) = csrf_token.verify(&form.authenticity_token) { return Flash::error( Redirect::to(uri!(new)), "invalid authenticity token", diff --git a/examples/minimal/templates/comments/new.html.hbs b/examples/minimal/templates/comments/new.html.hbs index 5d8c842..c8a5147 100644 --- a/examples/minimal/templates/comments/new.html.hbs +++ b/examples/minimal/templates/comments/new.html.hbs @@ -1,7 +1,7 @@ {{ flash }} - +