mirror of
https://github.com/kotovalexarian/rocket_csrf.git
synced 2025-02-10 15:34:27 -05:00
Fix example
This commit is contained in:
parent
2caf37e455
commit
d4d233526b
3 changed files with 942 additions and 334 deletions
1259
examples/minimal/Cargo.lock
generated
1259
examples/minimal/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,8 +6,8 @@ edition = "2018"
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.4.11"
|
||||
rocket = "0.5.0-rc.2"
|
||||
rocket_csrf = { path = "../.." }
|
||||
rocket_contrib = { version = "0.4.11", features = ["handlebars_templates"] }
|
||||
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["handlebars"] }
|
||||
serde = "1.0.117"
|
||||
serde_derive = "1.0.117"
|
||||
|
|
|
@ -5,10 +5,11 @@ extern crate rocket;
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use rocket::request::{FlashMessage, Form};
|
||||
use rocket::form::Form;
|
||||
use rocket::request::FlashMessage;
|
||||
use rocket::response::{Flash, Redirect};
|
||||
use rocket_contrib::templates::Template;
|
||||
use rocket_csrf::CsrfToken;
|
||||
use rocket_dyn_templates::Template;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct TemplateContext {
|
||||
|
@ -22,12 +23,12 @@ struct Comment {
|
|||
text: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite()
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
.attach(rocket_csrf::Fairing::default())
|
||||
.attach(Template::fairing())
|
||||
.mount("/", routes![index, new, create])
|
||||
.launch();
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
|
@ -39,7 +40,7 @@ fn index() -> Redirect {
|
|||
fn new(csrf_token: CsrfToken, flash: Option<FlashMessage>) -> Template {
|
||||
let template_context = TemplateContext {
|
||||
authenticity_token: csrf_token.authenticity_token().to_string(),
|
||||
flash: flash.map(|msg| format!("{}! {}", msg.name(), msg.msg())),
|
||||
flash: flash.map(|flash| flash.message().to_string()),
|
||||
};
|
||||
|
||||
Template::render("comments/new", &template_context)
|
||||
|
|
Loading…
Add table
Reference in a new issue