checking for open routes which require no aut in wall_entry

This commit is contained in:
shockrah 2020-06-02 01:29:05 -07:00
parent d02f2d9eb7
commit 68aeb50175

View File

@ -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,8 +26,17 @@ 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 {
fn open_route(path: &str) -> bool {
return path == routes::INVITE_JOIN
}
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 // Start by Checking if the api key is in our keystore
if open_route(path) {
AuthReason::OpenAuth
}
else {
if let Some(key) = params.get("key") { if let Some(key) = params.get("key") {
// (id, limit, current counter) // (id, limit, current counter)
let db_request: Result<(Conn, Option<(String, i32, i32)>), mysql_async::error::Error> = conn let db_request: Result<(Conn, Option<(String, i32, i32)>), mysql_async::error::Error> = conn
@ -42,7 +53,4 @@ pub async fn wall_entry(conn: Conn, params: &HashMap<&str, &str>) -> AuthReason
AuthReason::NoKey AuthReason::NoKey
} }
} }
pub fn wall_failure(resp: &Response<Body>) {
unimplemented!()
} }