user name+id now added to params and channels table now accepts channel_name
This commit is contained in:
parent
b8c4cee57f
commit
000a75c81f
@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS `messages`(
|
|||||||
`time` BIGINT NOT NULL,
|
`time` BIGINT NOT NULL,
|
||||||
`content` VARCHAR(2048) NOT NULL,
|
`content` VARCHAR(2048) NOT NULL,
|
||||||
`author_id` BIGINT UNSIGNED NOT NULL,
|
`author_id` BIGINT UNSIGNED NOT NULL,
|
||||||
`channel_id` BIGINT UNSIGNED NOT NULL,
|
`channel_name` VARCHAR(255) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
FOREIGN KEY (`author_id`) REFERENCES members(`id`),
|
FOREIGN KEY (`author_id`) REFERENCES members(`id`),
|
||||||
FOREIGN KEY (`channel_id`) REFERENCES channels(`id`)
|
FOREIGN KEY (`channel_id`) REFERENCES channels(`id`)
|
||||||
|
@ -14,7 +14,8 @@ pub enum AuthReason {
|
|||||||
fn open_route(path: &str) -> bool {
|
fn open_route(path: &str) -> bool {
|
||||||
return path == routes::INVITE_JOIN
|
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
|
// Start by Checking if the api key is in our keystore
|
||||||
if open_route(path) {
|
if open_route(path) {
|
||||||
Ok(AuthReason::OpenAuth)
|
Ok(AuthReason::OpenAuth)
|
||||||
@ -32,7 +33,11 @@ pub async fn wall_entry(path: &str, pool: &Pool, params: &serde_json::Value) ->
|
|||||||
match db_result {
|
match db_result {
|
||||||
Ok((_, row)) => {
|
Ok((_, row)) => {
|
||||||
match 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)
|
None => Ok(AuthReason::NoKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
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());
|
let pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
||||||
if let Ok(auth_result) = auth::wall_entry(path, &pool, ¶ms).await {
|
if let Ok(auth_result) = auth::wall_entry(path, &pool, &mut params).await {
|
||||||
// Deal with permissions errors at this point
|
// Deal with permissions errors at this point
|
||||||
match auth_result {
|
match auth_result {
|
||||||
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
|
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
|
||||||
|
@ -7,21 +7,12 @@ use hyper::{Response, Body, StatusCode};
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
|
||||||
use crate::db_types::{UBigInt, VarChar};
|
use crate::db_types::{UBigInt};
|
||||||
|
|
||||||
|
|
||||||
struct Message {
|
pub async fn insert_message_table(pool: &Pool, content: &Value, channel_name: &Value, author_id: UBigInt)
|
||||||
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)
|
|
||||||
-> Result<(), Error>{
|
-> Result<(), Error>{
|
||||||
match (content.as_str(), channel_id.as_u64()) {
|
match (content.as_str(), channel_name.as_str()) {
|
||||||
(Some(content), Some(channel)) => {
|
(Some(content), Some(channel)) => {
|
||||||
let conn = pool.get_conn().await?;
|
let conn = pool.get_conn().await?;
|
||||||
let time = Utc::now().timestamp();
|
let time = Utc::now().timestamp();
|
||||||
|
@ -24,6 +24,14 @@ delete_channel() {
|
|||||||
log_result good_delete_channel 200 $code "$result"
|
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
|
# Dispatcher to run our tests
|
||||||
if [ -z $1 ];then
|
if [ -z $1 ];then
|
||||||
for cmd in $active_tests;do
|
for cmd in $active_tests;do
|
||||||
|
Loading…
Reference in New Issue
Block a user