Removal of unused uses or random code that was dead anyway

This commit is contained in:
shockrah 2020-11-16 22:58:58 -08:00
parent cfc060b645
commit f0f0272c32
4 changed files with 6 additions and 109 deletions

View File

@ -9,7 +9,6 @@ use db::{member::Member, common::FromDB};
use db::Response;
// used when we create a new users for the first time
pub const BCRYPT_COST: u32 = 14;
pub enum AuthReason {
Good, //passed regular check
OpenAuth, // route does not require auth

View File

@ -58,7 +58,8 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
*response.body_mut() = Body::from(to_string(&row).unwrap_or("{}".into()));
},
db::Response::Empty => *response.status_mut() = StatusCode::NOT_FOUND,
db::Response::Other(msg) => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
// TODO: loggin
db::Response::Other(_msg) => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
}
},

View File

@ -1,65 +1,9 @@
use chrono::Utc;
use hyper::{Response, Body, StatusCode};
use hyper::header::HeaderValue;
use mysql_async::{Conn, Pool, error::Error as SqlError};
use mysql_async::prelude::{params, Queryable};
use serde::Serialize;
use mysql_async::Pool;
use db::{UBigInt, BigInt, Integer, VarChar};
use db::member::STATUS_ONLINE;
use db::common::FromDB;
use crate::auth;
#[derive(Serialize)]
pub struct Member {
pub id: UBigInt,
pub secret: VarChar,
pub name: VarChar,
pub joindate: BigInt,
pub status: Integer,
pub permissions: UBigInt,
}
pub async fn insert_new_member(p: &Pool, name: VarChar, perms: u64) -> Result<Member, SqlError> {
use crate::auth::generate_secret;
let conn: Conn = p.get_conn().await?;
let secret_raw: String = generate_secret();
let secret = match bcrypt::hash(&secret_raw, auth::BCRYPT_COST) {
Ok(value) => value,
Err(e) => panic!("\tCould not insert member due to bcrypt failure:\n\t\t{}",e)
};
let now: BigInt = Utc::now().timestamp();
let conn = conn.drop_exec(
"INSERT INTO members(secret, name, joindate, status, permissions)
VALUES(:secret, :name, :joindate, :status, :permissions)",
mysql_async::params!{
"secret" => secret.clone(),
"name" => name.clone(),
"joindate" => now,
"status" => STATUS_ONLINE,
"permissions" => perms
}).await?;
// now pull back the user from our db and return that row
let db_row_result: (Conn, Option<UBigInt>) = conn.first_exec(
"SELECT id FROM members WHERE secret = :secret",
params!{
"secret" => secret.clone()
}).await?;
Ok(Member {
id: db_row_result.1.unwrap(), // if we made it this far this shouldn't fail (i hope)
secret: secret_raw,
name: name,
joindate: now,
status: 0,
permissions: perms
})
}
pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
// TODO: at some point we should provide a way of not querying literally every user in

View File

@ -1,13 +1,6 @@
use std::borrow::Cow;
use mysql_async::{Pool, params};
use mysql_async::prelude::{Queryable};
use mysql_async::error::Error;
use mysql_async::Pool;
use hyper::{Response, Body, StatusCode};
use serde_json::Value;
use chrono::Utc;
use db::UBigInt;
pub async fn send_message(pool: &Pool, response: &mut Response<Body>, params: Value) {
@ -25,7 +18,8 @@ pub async fn send_message(pool: &Pool, response: &mut Response<Body>, params: Va
if let (Some(message), Some(cid)) = (content, channel) {
// call returns empty on sucess so we don't need to do anything
if let Err(issue) = db::messages::Message::send(pool, message, cid, author).await {
// TODO: loggin
if let Err(_issue) = db::messages::Message::send(pool, message, cid, author).await {
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
// log(send)
}
@ -66,46 +60,5 @@ mod messaging_tests {
assert_ne!(StatusCode::OK, resp.status());
}
#[tokio::test]#[ignore]
async fn send_message_good() {
use crate::members::insert_new_member;
use crate::perms::GENERAL_NEW;
use mysql_async::params;
use mysql_async::prelude::Queryable;
use crate::testing::tmp_channel_params;
let p = get_pool();
let mut resp = hyper_resp();
let tmp_chan = tmp_channel_params(&p, "sample").await;
const TMP_NAME: &'static str = "bs user";
let temp_member = insert_new_member(&p, TMP_NAME.into(), GENERAL_NEW).await.unwrap();
let params: Value = serde_json::from_str(&format!(r#"
{{
"id": {},
"channel": "{}",
"content": "bs message"
}}
"#, temp_member.id, tmp_chan.name)).unwrap();
super::send_message(&p, &mut resp, params).await;
if resp.status() == StatusCode::BAD_REQUEST {
panic!("{:?}", resp.body());
}
// Destroy the the message and the user that we created
let conn = match p.get_conn().await {
Ok(c) => c,
Err(e) => panic!("Could not get connection to db during send_message_good:\nIssue:\t{}", e)
};
let conn = conn.drop_exec("DELETE FROM messages WHERE author_id = :id", params!{"id" => temp_member.id}).await.unwrap();
let conn = conn.drop_exec("DELETE FROM members WHERE id = :id", params!{"id" => temp_member.id}).await.unwrap();
let _ = conn.drop_exec("DELETE FROM channels WHERE name = :name", params!{"name" => tmp_chan.name}).await;
}
}