user name+id now added to params and channels table now accepts channel_name

This commit is contained in:
shockrah 2020-07-30 23:50:03 -07:00
parent b8c4cee57f
commit 000a75c81f
5 changed files with 21 additions and 17 deletions

View File

@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS `messages`(
`time` BIGINT NOT NULL,
`content` VARCHAR(2048) NOT NULL,
`author_id` BIGINT UNSIGNED NOT NULL,
`channel_id` BIGINT UNSIGNED NOT NULL,
`channel_name` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`author_id`) REFERENCES members(`id`),
FOREIGN KEY (`channel_id`) REFERENCES channels(`id`)

View File

@ -14,7 +14,8 @@ pub enum AuthReason {
fn open_route(path: &str) -> bool {
return path == routes::INVITE_JOIN
}
pub async fn wall_entry(path: &str, pool: &Pool, params: &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> {
use serde_json::json;
// Start by Checking if the api key is in our keystore
if open_route(path) {
Ok(AuthReason::OpenAuth)
@ -32,7 +33,11 @@ pub async fn wall_entry(path: &str, pool: &Pool, params: &serde_json::Value) ->
match db_result {
Ok((_, row)) => {
match row{
Some(_) => Ok(AuthReason::Good),
Some(user_row) => {
params["userid"] = json!(user_row.0);
params["username"] = json!(user_row.1);
Ok(AuthReason::Good)
},
None => Ok(AuthReason::NoKey)
}
}

View File

@ -81,9 +81,9 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
let params_res = http_params::parse_params(&mut body).await;
if let Ok(params) = params_res {
if let Ok(mut params) = params_res {
let pool = Pool::new(&env::var("DATABASE_URL").unwrap());
if let Ok(auth_result) = auth::wall_entry(path, &pool, &params).await {
if let Ok(auth_result) = auth::wall_entry(path, &pool, &mut params).await {
// Deal with permissions errors at this point
match auth_result {
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,

View File

@ -7,21 +7,12 @@ use hyper::{Response, Body, StatusCode};
use serde_json::Value;
use chrono::Utc;
use crate::db_types::{UBigInt, VarChar};
use crate::db_types::{UBigInt};
struct Message {
id: UBigInt,
content: Option<VarChar>, // some messages later might only have file attachments and not text content
author_id: UBigInt,
channel_id: UBigInt,
permissions: UBigInt,
}
pub async fn insert_message_table(pool: &Pool, content: &Value, channel_id: &Value, author_id: UBigInt)
pub async fn insert_message_table(pool: &Pool, content: &Value, channel_name: &Value, author_id: UBigInt)
-> Result<(), Error>{
match (content.as_str(), channel_id.as_u64()) {
match (content.as_str(), channel_name.as_str()) {
(Some(content), Some(channel)) => {
let conn = pool.get_conn().await?;
let time = Utc::now().timestamp();

View File

@ -24,6 +24,14 @@ delete_channel() {
log_result good_delete_channel 200 $code "$result"
}
send_message() {
kv='{"secret":"secret", "content":"message sample", "channel":123}'
result=$($crl $POST $url/message/send -d "$kv")
code=$(echo "$result" | grep HTTP\/1.1 | awk '{print $2}')
# non-existant channel for now but whatever ignore for now
log_result good_send_message 200 $code "$result"
}
# Dispatcher to run our tests
if [ -z $1 ];then
for cmd in $active_tests;do