Make guard struct field private
This commit is contained in:
parent
1500b7c890
commit
8c887d685a
|
@ -73,7 +73,7 @@ to use it in [templates](https://rocket.rs/v0.4/guide/responses/#templates):
|
|||
```rust
|
||||
#[get("/comments/new")]
|
||||
fn new(csrf_token: CsrfToken) -> Template {
|
||||
let authenticity_token: String = csrf_token.0;
|
||||
let authenticity_token: &str = csrf_token.authenticity_token();
|
||||
|
||||
// your code
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ fn index() -> Redirect {
|
|||
#[get("/comments/new")]
|
||||
fn new(csrf_token: CsrfToken, flash: Option<FlashMessage>) -> Template {
|
||||
let template_context = TemplateContext {
|
||||
authenticity_token: csrf_token.0,
|
||||
authenticity_token: csrf_token.authenticity_token().to_string(),
|
||||
flash: flash.map(|msg| format!("{}! {}", msg.name(), msg.msg())),
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ const RAW_TOKEN_LENGTH: usize = 32;
|
|||
|
||||
pub struct Fairing;
|
||||
|
||||
pub struct CsrfToken(pub String);
|
||||
pub struct CsrfToken(String);
|
||||
|
||||
pub struct VerificationFailure;
|
||||
|
||||
|
@ -24,6 +24,10 @@ impl Fairing {
|
|||
}
|
||||
|
||||
impl CsrfToken {
|
||||
pub fn authenticity_token(&self) -> &str {
|
||||
self.0.as_ref()
|
||||
}
|
||||
|
||||
pub fn verify(&self, form_authenticity_token: &str)
|
||||
-> Result<(), VerificationFailure>
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ fn rocket() -> rocket::Rocket {
|
|||
|
||||
#[get("/")]
|
||||
fn index(csrf_token: CsrfToken) -> String {
|
||||
csrf_token.0
|
||||
csrf_token.authenticity_token().to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue