1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +01:00

tweak docs

This commit is contained in:
Rob Ede 2022-03-01 04:23:51 +00:00
parent 673b77a765
commit 12f6db3755
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933

View File

@ -7,7 +7,7 @@
//! //!
//! To access current request identity, use the [`Identity`] extractor. //! To access current request identity, use the [`Identity`] extractor.
//! //!
//! ```no_run //! ```
//! use actix_web::*; //! use actix_web::*;
//! use actix_identity::{Identity, CookieIdentityPolicy, IdentityService}; //! use actix_identity::{Identity, CookieIdentityPolicy, IdentityService};
//! //!
@ -23,33 +23,30 @@
//! //!
//! #[post("/login")] //! #[post("/login")]
//! async fn login(id: Identity) -> HttpResponse { //! async fn login(id: Identity) -> HttpResponse {
//! id.remember("User1".to_owned()); // <- remember identity //! // remember identity
//! id.remember("User1".to_owned());
//! HttpResponse::Ok().finish() //! HttpResponse::Ok().finish()
//! } //! }
//! //!
//! #[post("/logout")] //! #[post("/logout")]
//! async fn logout(id: Identity) -> HttpResponse { //! async fn logout(id: Identity) -> HttpResponse {
//! id.forget(); // <- remove identity //! // remove identity
//! id.forget();
//! HttpResponse::Ok().finish() //! HttpResponse::Ok().finish()
//! } //! }
//! //!
//! #[actix_web::main] //! HttpServer::new(move || {
//! async fn main() -> std::io::Result<()> { //! // create cookie identity backend (inside closure, since policy is not Clone)
//! HttpServer::new(move || { //! let policy = CookieIdentityPolicy::new(&[0; 32])
//! // create cookie identity backend //! .name("auth-cookie")
//! let policy = CookieIdentityPolicy::new(&[0; 32]) //! .secure(false);
//! .name("auth-cookie")
//! .secure(false);
//! //!
//! App::new() //! App::new()
//! // wrap policy into middleware identity middleware //! // wrap policy into middleware identity middleware
//! .wrap(IdentityService::new(policy)) //! .wrap(IdentityService::new(policy))
//! .service(services![index, login, logout]) //! .service(services![index, login, logout])
//! }) //! })
//! .bind(("0.0.0.0", 8080u16))? //! # ;
//! .run()
//! .await
//! }
//! ``` //! ```
#![deny(rust_2018_idioms, nonstandard_style)] #![deny(rust_2018_idioms, nonstandard_style)]