checking for open routes which require no aut in wall_entry
This commit is contained in:
parent
d02f2d9eb7
commit
68aeb50175
@ -1,10 +1,12 @@
|
|||||||
use mysql_async::Conn;
|
use mysql_async::Conn;
|
||||||
use mysql_async::prelude::{params, Queryable};
|
use mysql_async::prelude::{params, Queryable};
|
||||||
use hyper::{Response, Body};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::routes;
|
||||||
|
|
||||||
pub enum AuthReason {
|
pub enum AuthReason {
|
||||||
Good,
|
Good, //passed regular check
|
||||||
|
OpenAuth, // route does not require auth
|
||||||
LimitPassed,
|
LimitPassed,
|
||||||
NoKey,
|
NoKey,
|
||||||
InternalFailure,
|
InternalFailure,
|
||||||
@ -24,25 +26,31 @@ fn check_key_row(row: Option<(String, i32, i32)>) -> AuthReason {
|
|||||||
None => NoKey
|
None => NoKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub async fn wall_entry(conn: Conn, params: &HashMap<&str, &str>) -> AuthReason {
|
|
||||||
// Start by Checking if the api key is in our keystore
|
|
||||||
if let Some(key) = params.get("key") {
|
|
||||||
// (id, limit, current counter)
|
|
||||||
let db_request: Result<(Conn, Option<(String, i32, i32)>), mysql_async::error::Error> = conn
|
|
||||||
.first_exec(r"SELECT * FROM keys WHERE id = :id ", mysql_async::params!{ "id" => key})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// Error case should probably have some kind of error checking
|
fn open_route(path: &str) -> bool {
|
||||||
match db_request {
|
return path == routes::INVITE_JOIN
|
||||||
Ok(db_tup) => check_key_row(db_tup.1),
|
}
|
||||||
Err(_) => AuthReason::InternalFailure
|
|
||||||
}
|
pub async fn wall_entry(path: &str, conn: Conn, params: &HashMap<&str, &str>) -> AuthReason {
|
||||||
|
// Start by Checking if the api key is in our keystore
|
||||||
|
if open_route(path) {
|
||||||
|
AuthReason::OpenAuth
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
AuthReason::NoKey
|
if let Some(key) = params.get("key") {
|
||||||
|
// (id, limit, current counter)
|
||||||
|
let db_request: Result<(Conn, Option<(String, i32, i32)>), mysql_async::error::Error> = conn
|
||||||
|
.first_exec(r"SELECT * FROM keys WHERE id = :id ", mysql_async::params!{ "id" => key})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
// Error case should probably have some kind of error checking
|
||||||
|
match db_request {
|
||||||
|
Ok(db_tup) => check_key_row(db_tup.1),
|
||||||
|
Err(_) => AuthReason::InternalFailure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AuthReason::NoKey
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wall_failure(resp: &Response<Body>) {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user