fistinc-auth 0.1.0

Paging types for Fist Inc bank
Documentation
use actix_http::Payload;
use actix_web::{Error, FromRequest, HttpRequest};
use email_address::EmailAddress;
use futures::future::{ok, Ready};
use uuid::Uuid;
use crate::domain::entity::Role;

pub struct UserIdentity {
    pub email: EmailAddress,
    pub role: Role,
    pub user_id: Uuid,
}

impl FromRequest for UserIdentity {
    type Error = Error;
    type Future = Ready<Result<UserIdentity, Error>>;
    type Config = ();

    #[inline]
    fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
        let data = req
            .extensions()
            .get::<UserIdentity>()
            .map(|user_identity| UserIdentity {
                email: user_identity.email.clone(),
                role: user_identity.role.clone(),
                user_id: user_identity.user_id,
            })
            .unwrap(); // todo: may be not use unwrap?
        ok(data)
    }
}