chore: clean up, rename types.rs to server.rs

This commit is contained in:
hexlocation 2025-07-29 12:35:03 +02:00
parent a8bc61f40c
commit 0c68399210
9 changed files with 110 additions and 41 deletions

View file

@ -27,7 +27,26 @@ pub struct Api {
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct Client {
pub name: String,
pub secret: String,
pub hashed_secret: String,
}
impl Client {
pub async fn verify(us: String, config: Config) -> bool {
// us stands for user:secret btw
let us_split: Vec<&str> = us.split(':').collect();
let name = us_split.first().unwrap();
let secret = us_split.last().unwrap();
let client: Client = config
.clients
.into_iter()
.filter(|x| x.name.eq(name))
.nth(0)
.unwrap();
return bcrypt::verify(secret, client.hashed_secret.as_str()).unwrap();
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]