capy-auth 0.10.0

Optional database-backed browser sessions and explicit authorization for Capy.
Documentation
// Redacted database values also keep SeaORM ActiveModel Debug safe.
#[derive(Clone, PartialEq, Eq, sea_orm::DeriveValueType)]
pub(crate) struct DbSecret(pub String);
impl std::fmt::Debug for DbSecret {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("DbSecret([REDACTED])")
    }
}
// Native SeaORM persistence models. No serialization and deliberately redacted Debug.
pub(crate) mod verification {
    use sea_orm::entity::prelude::*;
    #[derive(Clone, PartialEq, DeriveEntityModel)]
    #[sea_orm(table_name = "email_verification_tokens")]
    pub struct Model {
        #[sea_orm(primary_key, auto_increment = false)]
        pub user_id: i64,
        pub token_hash: super::DbSecret,
        pub email: super::DbSecret,
        pub expires_at: i64,
    }
    impl std::fmt::Debug for Model {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            f.write_str("verification::Model([REDACTED])")
        }
    }
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
    impl ActiveModelBehavior for ActiveModel {}
}
pub(crate) mod user {
    use sea_orm::entity::prelude::*;
    #[derive(Clone, PartialEq, DeriveEntityModel)]
    #[sea_orm(table_name = "users")]
    pub struct Model {
        #[sea_orm(primary_key)]
        pub id: i64,
        pub name: String,
        pub email: String,
        pub password_hash: super::DbSecret,
        pub email_verified_at: Option<i64>,
        pub created_at: i64,
        pub updated_at: i64,
    }
    impl std::fmt::Debug for Model {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            f.write_str("user::Model([REDACTED])")
        }
    }
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
    impl ActiveModelBehavior for ActiveModel {}
}
pub(crate) mod session {
    use sea_orm::entity::prelude::*;
    #[derive(Clone, PartialEq, DeriveEntityModel)]
    #[sea_orm(table_name = "sessions")]
    pub struct Model {
        #[sea_orm(primary_key, auto_increment = false)]
        pub token_hash: String,
        pub user_id: Option<i64>,
        pub csrf_token: super::DbSecret,
        pub created_at: i64,
        pub last_seen_at: i64,
        pub expires_at: i64,
    }
    impl std::fmt::Debug for Model {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            f.write_str("session::Model([REDACTED])")
        }
    }
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
    impl ActiveModelBehavior for ActiveModel {}
}
pub(crate) mod reset {
    use sea_orm::entity::prelude::*;
    #[derive(Clone, PartialEq, DeriveEntityModel)]
    #[sea_orm(table_name = "password_reset_tokens")]
    pub struct Model {
        #[sea_orm(primary_key, auto_increment = false)]
        pub token_hash: String,
        pub user_id: i64,
        pub created_at: i64,
        pub expires_at: i64,
    }
    impl std::fmt::Debug for Model {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            f.write_str("reset::Model([REDACTED])")
        }
    }
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
    impl ActiveModelBehavior for ActiveModel {}
}