Moved the check of existence of a master password into master_pass.rs, added buttons for /get_account

This commit is contained in:
2023-05-04 19:03:03 +03:00
parent 17e4f1892c
commit 83aa2c90b1
4 changed files with 44 additions and 21 deletions

View File

@ -2,7 +2,7 @@
use rand::{rngs::OsRng, RngCore};
use scrypt::{scrypt, Params};
use sea_orm::{entity::prelude::*, ActiveValue::Set};
use sea_orm::{entity::prelude::*, ActiveValue::Set, QuerySelect};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "master_pass")]
@ -54,4 +54,16 @@ impl Entity {
let password_hash = hash_password(master_pass.as_ref(), &model.salt)?;
Ok(Some(password_hash == model.password_hash))
}
/// Checks if the master password for the user exists
pub async fn exists(user_id: u64, db: &DatabaseConnection) -> crate::Result<bool> {
let id = Self::find()
.select_only()
.column(Column::UserId)
.filter(Column::UserId.eq(user_id))
.into_tuple::<u64>()
.one(db)
.await?;
Ok(id.is_some())
}
}