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