Make guard struct field private

This commit is contained in:
Alex Kotov 2020-10-18 12:29:55 +05:00
parent 1500b7c890
commit 8c887d685a
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 8 additions and 4 deletions

View File

@ -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
}

View File

@ -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())),
};

View File

@ -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>
{

View File

@ -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]