making routes::is_open behavior a lot more clear
moved /join to be handled by the dynamic path handler
This commit is contained in:
parent
32ee49ed08
commit
5d1b95bec6
@ -15,10 +15,6 @@ pub enum AuthReason {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn open_route(path: &str) -> bool {
|
|
||||||
return path == routes::INVITE_JOIN
|
|
||||||
}
|
|
||||||
|
|
||||||
fn valid_user(secret: &str, row: &Option<(VarChar, VarChar, BigInt, Integer, UBigInt)>) -> bool {
|
fn valid_user(secret: &str, row: &Option<(VarChar, VarChar, BigInt, Integer, UBigInt)>) -> bool {
|
||||||
match row {
|
match row {
|
||||||
Some(row) => {
|
Some(row) => {
|
||||||
@ -33,7 +29,7 @@ fn valid_user(secret: &str, row: &Option<(VarChar, VarChar, BigInt, Integer, UBi
|
|||||||
|
|
||||||
pub async fn wall_entry(path: &str, pool: &Pool, params: &mut serde_json::Value) -> Result<AuthReason, mysql_async::error::Error> {
|
pub async fn wall_entry(path: &str, pool: &Pool, params: &mut serde_json::Value) -> Result<AuthReason, mysql_async::error::Error> {
|
||||||
// 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) {
|
if routes::is_open(path) {
|
||||||
Ok(AuthReason::OpenAuth)
|
Ok(AuthReason::OpenAuth)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -46,7 +46,6 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method,
|
|||||||
use routes::resolve_dynamic_route;
|
use routes::resolve_dynamic_route;
|
||||||
match (meth, path) {
|
match (meth, path) {
|
||||||
/* INVITES */
|
/* INVITES */
|
||||||
(&Method::GET, routes::INVITE_JOIN) => invites::join(pool, resp, params).await,
|
|
||||||
(&Method::GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await,
|
(&Method::GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await,
|
||||||
/* CHANNELS */
|
/* CHANNELS */
|
||||||
(&Method::GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await,
|
(&Method::GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await,
|
||||||
@ -63,9 +62,13 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method,
|
|||||||
// Computatinoal bounds are really of no concern with this api since
|
// Computatinoal bounds are really of no concern with this api since
|
||||||
// we're not doing any heavy calculations at any point
|
// we're not doing any heavy calculations at any point
|
||||||
if let Some(route) = resolve_dynamic_route(path) {
|
if let Some(route) = resolve_dynamic_route(path) {
|
||||||
*resp.status_mut() = StatusCode::OK;
|
match (meth, route.base.as_str()) {
|
||||||
println!("\tStatic part: {}", route.base);
|
(&Method::GET, routes::DYN_JOIN) => invites::join(pool, resp, params).await,
|
||||||
println!("\tDynamic part: {}", route.dynamic);
|
_ => {
|
||||||
|
println!("\tNOT FOUND: {}: {}", meth, path);
|
||||||
|
*resp.status_mut() = StatusCode::NOT_FOUND
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println!("\tNOT FOUND: {}: {}", meth, path);
|
println!("\tNOT FOUND: {}: {}", meth, path);
|
||||||
|
@ -9,11 +9,12 @@ pub const MESSAGE_SEND: &'static str = "/message/send"; // requires @content
|
|||||||
pub const SERVER_META: &'static str = "/meta"; // open
|
pub const SERVER_META: &'static str = "/meta"; // open
|
||||||
|
|
||||||
// potentially adding more bases later
|
// potentially adding more bases later
|
||||||
const DYNAMIC_ROUTE_BASES: [(&'static str, bool);3] = [
|
pub const DYNAMIC_ROUTE_BASES: [(&'static str, bool);3] = [
|
||||||
("/join", true), // open
|
("/join", true), // open
|
||||||
("/public", true), // open : valid sections := neighbors|rules|description
|
("/public", true), // open : valid sections := neighbors|rules|description
|
||||||
("/user", false), // TODO: valid sections := /meta/<name>|/dm/<name>
|
("/user", false), // TODO: valid sections := /meta/<name>|/dm/<name>
|
||||||
];
|
];
|
||||||
|
pub const DYN_JOIN: &'static str = DYNAMIC_ROUTE_BASES[0].0;
|
||||||
|
|
||||||
pub struct DynRoute {
|
pub struct DynRoute {
|
||||||
pub base: String,
|
pub base: String,
|
||||||
@ -43,8 +44,11 @@ pub fn resolve_dynamic_route(uri: &str) -> Option<DynRoute> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_open(path: &str) -> bool {
|
pub fn is_open(path: &str) -> bool {
|
||||||
let mut ret = false;
|
/*
|
||||||
ret = path == SERVER_META;
|
* Simple interface for determining if a route/base is open
|
||||||
|
* i.e. requires authentication or not
|
||||||
|
*/
|
||||||
|
let mut ret = path == SERVER_META;
|
||||||
for route in DYNAMIC_ROUTE_BASES.iter() {
|
for route in DYNAMIC_ROUTE_BASES.iter() {
|
||||||
if route.1 == true || ret == true{
|
if route.1 == true || ret == true{
|
||||||
ret = true;
|
ret = true;
|
||||||
@ -53,3 +57,4 @@ pub fn is_open(path: &str) -> bool {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user