1
0
Fork 0
forked from alemi/upub

feat: added sessions with credentials

This commit is contained in:
əlemi 2024-03-24 04:03:22 +01:00
parent 2673860106
commit 7251a3e92c
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 67 additions and 3 deletions

View file

@ -16,8 +16,26 @@ impl MigrationTrait for Migration {
.not_null() .not_null()
.primary_key() .primary_key()
) )
.col(ColumnDef::new(Credentials::Email).boolean().not_null()) .col(ColumnDef::new(Credentials::Email).string().not_null())
.col(ColumnDef::new(Credentials::Password).boolean().not_null()) .col(ColumnDef::new(Credentials::Password).string().not_null())
.to_owned()
)
.await?;
manager
.create_table(
Table::create()
.table(Sessions::Table)
.col(
ColumnDef::new(Sessions::Id)
.integer()
.not_null()
.auto_increment()
.primary_key()
)
.col(ColumnDef::new(Sessions::Actor).string().not_null())
.col(ColumnDef::new(Sessions::Session).string().not_null())
.col(ColumnDef::new(Sessions::Expires).date_time().not_null())
.to_owned() .to_owned()
) )
.await?; .await?;
@ -41,3 +59,12 @@ enum Credentials {
Email, Email,
Password, Password,
} }
#[derive(DeriveIden)]
enum Sessions {
Table,
Id, // TODO here ID is a number but in Credentials it's the actor ID (String) ??? weird!!
Actor,
Session,
Expires,
}

29
src/model/session.rs Normal file
View file

@ -0,0 +1,29 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "sessions")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub actor: String,
pub session: String,
pub expires: ChronoDateTimeUtc,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::Actor",
to = "super::user::Column::Id"
)]
User,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -7,7 +7,6 @@ use crate::{activitypub, activitystream::object::{collection::Collection, actor:
#[sea_orm(table_name = "users")] #[sea_orm(table_name = "users")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key)] #[sea_orm(primary_key)]
/// must be full AP ID, since they are unique over the network
pub id: String, pub id: String,
pub domain: String, pub domain: String,
pub actor_type: ActorType, pub actor_type: ActorType,
@ -77,6 +76,9 @@ pub enum Relation {
#[sea_orm(has_one = "super::credential::Entity")] #[sea_orm(has_one = "super::credential::Entity")]
Credential, Credential,
#[sea_orm(has_many = "super::session::Entity")]
Session,
} }
impl Related<super::activity::Entity> for Entity { impl Related<super::activity::Entity> for Entity {
@ -103,4 +105,10 @@ impl Related<super::credential::Entity> for Entity {
} }
} }
impl Related<super::session::Entity> for Entity {
fn to() -> RelationDef {
Relation::Session.def()
}
}
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}