chore: clean up, rename types.rs to server.rs
This commit is contained in:
parent
a8bc61f40c
commit
0c68399210
9 changed files with 110 additions and 41 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue