[−][src]Struct actix_web::middleware::identity::Identity
The extractor type to obtain your identity from a request.
use actix_web::*; use actix_web::middleware::identity::Identity; fn index(id: Identity) -> Result<String> { // access request identity if let Some(id) = id.identity() { Ok(format!("Welcome! {}", id)) } else { Ok("Welcome Anonymous!".to_owned()) } } fn login(id: Identity) -> HttpResponse { id.remember("User1".to_owned()); // <- remember identity HttpResponse::Ok().finish() } fn logout(id: Identity) -> HttpResponse { id.forget(); // <- remove identity HttpResponse::Ok().finish() }
Methods
impl Identity
[src]
pub fn identity(&self) -> Option<String>
[src]
Return the claimed identity of the user associated request or
None
if no identity can be found associated with the request.
pub fn remember(&self, identity: String)
[src]
Remember identity.
pub fn forget(&self)
[src]
This method is used to 'forget' the current identity on subsequent requests.
Trait Implementations
impl<P> FromRequest<P> for Identity
[src]
Extractor implementation for Identity type.
use actix_web::middleware::identity::Identity; fn index(id: Identity) -> String { // access request identity if let Some(id) = id.identity() { format!("Welcome! {}", id) } else { "Welcome Anonymous!".to_owned() } }
type Error = Error
The associated error which can be returned.
type Future = Result<Identity, Error>
Future that resolves to a Self
fn from_request(req: &HttpRequest, _: &mut Payload<P>) -> Self::Future
[src]
fn extract(req: &HttpRequest) -> Self::Future
[src]
Convert request to a Self Read more
impl Clone for Identity
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.