backend: add admin flag

This commit is contained in:
Sphereso 2024-07-11 22:48:16 +02:00
parent 359bfc5ced
commit 4c30cd201e
3 changed files with 13 additions and 2 deletions

View file

@ -19,6 +19,7 @@ pub struct Model {
pub name: String, pub name: String,
pub email: String, pub email: String,
pub hash: String, pub hash: String,
pub admin: bool,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
@ -27,6 +28,7 @@ pub enum Column {
Name, Name,
Email, Email,
Hash, Hash,
Admin,
} }
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
@ -52,6 +54,7 @@ impl ColumnTrait for Column {
Self::Name => ColumnType::String(None).def(), Self::Name => ColumnType::String(None).def(),
Self::Email => ColumnType::String(None).def().unique(), Self::Email => ColumnType::String(None).def().unique(),
Self::Hash => ColumnType::String(None).def(), Self::Hash => ColumnType::String(None).def(),
Self::Admin => ColumnType::Boolean.def(),
} }
} }
} }

View file

@ -21,6 +21,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(User::Name).string().not_null()) .col(ColumnDef::new(User::Name).string().not_null())
.col(ColumnDef::new(User::Email).string().not_null().unique_key()) .col(ColumnDef::new(User::Email).string().not_null().unique_key())
.col(ColumnDef::new(User::Hash).string().not_null()) .col(ColumnDef::new(User::Hash).string().not_null())
.col(ColumnDef::new(User::Admin).boolean().not_null())
.to_owned(), .to_owned(),
) )
.await .await
@ -40,4 +41,5 @@ enum User {
Name, Name,
Email, Email,
Hash, Hash,
Admin,
} }

View file

@ -17,8 +17,13 @@ impl MigrationTrait for Migration {
.expect("Generating Admin Password Hash failed"); .expect("Generating Admin Password Hash failed");
let insert = Query::insert() let insert = Query::insert()
.into_table(User::Table) .into_table(User::Table)
.columns([User::Name, User::Email, User::Hash]) .columns([User::Name, User::Email, User::Hash, User::Admin])
.values_panic(["admin".into(), "admin".into(), hash.to_string().into()]) .values_panic([
"admin".into(),
"admin".into(),
hash.to_string().into(),
true.into(),
])
.to_owned(); .to_owned();
manager.exec_stmt(insert).await?; manager.exec_stmt(insert).await?;
@ -36,4 +41,5 @@ enum User {
Name, Name,
Email, Email,
Hash, Hash,
Admin,
} }