[][src]Trait actix_web::middleware::identity::RequestIdentity

pub trait RequestIdentity {
    fn identity(&self) -> Option<String>;
fn remember(&self, identity: String);
fn forget(&self); }

The helper trait to obtain your identity from a request.

use actix_web::middleware::identity::RequestIdentity;
use actix_web::*;

fn index(req: HttpRequest) -> Result<String> {
    // access request identity
    if let Some(id) = req.identity() {
        Ok(format!("Welcome! {}", id))
    } else {
        Ok("Welcome Anonymous!".to_owned())
    }
}

fn login(mut req: HttpRequest) -> HttpResponse {
    req.remember("User1".to_owned()); // <- remember identity
    HttpResponse::Ok().finish()
}

fn logout(mut req: HttpRequest) -> HttpResponse {
    req.forget(); // <- remove identity
    HttpResponse::Ok().finish()
}

Required Methods

Return the claimed identity of the user associated request or None if no identity can be found associated with the request.

Remember identity.

This method is used to 'forget' the current identity on subsequent requests.

Implementors

impl<S> RequestIdentity for HttpRequest<S>
[src]