feat: added sessions with credentials
This commit is contained in:
parent
2673860106
commit
7251a3e92c
3 changed files with 67 additions and 3 deletions
|
@ -16,8 +16,26 @@ impl MigrationTrait for Migration {
|
|||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Credentials::Email).boolean().not_null())
|
||||
.col(ColumnDef::new(Credentials::Password).boolean().not_null())
|
||||
.col(ColumnDef::new(Credentials::Email).string().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()
|
||||
)
|
||||
.await?;
|
||||
|
@ -41,3 +59,12 @@ enum Credentials {
|
|||
Email,
|
||||
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
29
src/model/session.rs
Normal 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 {}
|
|
@ -7,7 +7,6 @@ use crate::{activitypub, activitystream::object::{collection::Collection, actor:
|
|||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
/// must be full AP ID, since they are unique over the network
|
||||
pub id: String,
|
||||
pub domain: String,
|
||||
pub actor_type: ActorType,
|
||||
|
@ -77,6 +76,9 @@ pub enum Relation {
|
|||
|
||||
#[sea_orm(has_one = "super::credential::Entity")]
|
||||
Credential,
|
||||
|
||||
#[sea_orm(has_many = "super::session::Entity")]
|
||||
Session,
|
||||
}
|
||||
|
||||
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 {}
|
||||
|
|
Loading…
Reference in a new issue