mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-17 21:41:20 +00:00
feat: admin session tokens
This commit is contained in:
parent
28b1058752
commit
82d718a7f0
3 changed files with 13 additions and 62 deletions
|
|
@ -1,9 +1,8 @@
|
|||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20221024_111310_create_admin;
|
||||
mod m20221024_121621_create_candidate;
|
||||
mod m20221024_124701_create_parent;
|
||||
mod m20221024_134454_fill_admin;
|
||||
mod m20221024_134454_insert_sample_admin;
|
||||
mod m20221025_154422_create_session;
|
||||
mod m20221027_194728_session_create_user_fk;
|
||||
mod m20221030_133428_parent_create_candidate_fk;
|
||||
|
|
@ -13,10 +12,9 @@ pub struct Migrator;
|
|||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20221024_111310_create_admin::Migration),
|
||||
Box::new(m20221024_121621_create_candidate::Migration),
|
||||
Box::new(m20221024_124701_create_parent::Migration),
|
||||
Box::new(m20221024_134454_fill_admin::Migration::default()),
|
||||
Box::new(m20221024_134454_insert_sample_admin::Migration::default()),
|
||||
Box::new(m20221025_154422_create_session::Migration),
|
||||
Box::new(m20221027_194728_session_create_user_fk::Migration),
|
||||
Box::new(m20221030_133428_parent_create_candidate_fk::Migration),
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Admin::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Admin::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Admin::Name).string().not_null())
|
||||
.col(ColumnDef::new(Admin::PublicKey).string().not_null())
|
||||
.col(ColumnDef::new(Admin::PrivateKeyHash).text().not_null())
|
||||
.col(ColumnDef::new(Admin::PasswordHash).string().not_null())
|
||||
.col(ColumnDef::new(Admin::CreatedAt).date_time().not_null())
|
||||
.col(ColumnDef::new(Admin::UpdatedAt).date_time().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Admin::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Admin {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
PublicKey,
|
||||
PrivateKeyHash,
|
||||
PasswordHash,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use chrono::Local;
|
||||
use entity::admin;
|
||||
use entity::{candidate};
|
||||
use sea_orm_migration::{
|
||||
prelude::*,
|
||||
sea_orm::{ActiveModelTrait, Set},
|
||||
|
|
@ -7,20 +7,22 @@ use sea_orm_migration::{
|
|||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration {
|
||||
admin: admin::ActiveModel,
|
||||
candidate: candidate::ActiveModel,
|
||||
}
|
||||
|
||||
impl Default for Migration {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
admin: admin::ActiveModel {
|
||||
id: Set(1),
|
||||
name: Set("Administrátor Pepa".to_owned()),
|
||||
candidate: candidate::ActiveModel {
|
||||
application: Set(1),
|
||||
name: Set(Some("Administrátor Pepa".to_owned())),
|
||||
public_key: Set("lorem ipsum".to_owned()),
|
||||
private_key_hash: Set("lorem ipsum".to_owned()),
|
||||
password_hash: Set("lorem ipsum".to_owned()),
|
||||
private_key: Set("lorem ipsum".to_owned()),
|
||||
code: Set("$argon2id$v=19$m=4096,t=3,p=1$V2M1eENXcnJvenhqTVF1Yw$xwriCZexpzF7Qtj9lwq0Sw".to_owned()),
|
||||
personal_identification_number: Set("ADMIN".to_owned()),
|
||||
created_at: Set(Local::now().naive_local()),
|
||||
updated_at: Set(Local::now().naive_local()),
|
||||
is_admin: Set(true),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
@ -32,7 +34,7 @@ impl MigrationTrait for Migration {
|
|||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
let db = manager.get_connection();
|
||||
|
||||
self.admin.to_owned().insert(db).await?;
|
||||
self.candidate.to_owned().insert(db).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -40,7 +42,7 @@ impl MigrationTrait for Migration {
|
|||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
let db = manager.get_connection();
|
||||
|
||||
self.admin.to_owned().delete(db).await?;
|
||||
self.candidate.to_owned().delete(db).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Reference in a new issue