From 949cf74a3165fc8cf99af5db6b538c2bbbe9d27c Mon Sep 17 00:00:00 2001 From: CatAClock Date: Tue, 24 Jun 2025 05:38:13 +0000 Subject: [PATCH] Delete src/API/mod.rs --- src/API/mod.rs | 90 -------------------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 src/API/mod.rs diff --git a/src/API/mod.rs b/src/API/mod.rs deleted file mode 100644 index d0bd225..0000000 --- a/src/API/mod.rs +++ /dev/null @@ -1,90 +0,0 @@ -use postgres::{Client, NoTls}; - -pub fn Login(Username: &str, Password: &str) -> Result, Box>{ - let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - - let Table = Client.query("SELECT 1 - FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_TYPE='BASE TABLE' - AND TABLE_NAME='person'", &[]); - // Check if the table doesn't exists. Or does? - match Table { - Ok(_) => { - // Check if the table exists. - if Table?.len() == 0 { - Client.batch_execute(" - CREATE TABLE person ( - id SERIAL PRIMARY KEY, - username TEXT NOT NULL, - password TEXT NOT NULL - )")?; - } - }, - Err(_) => () - } - if Client.query("SELECT username, password FROM person WHERE username = $1", &[&Username])?.len() != 0 { - let mut Response: Vec = Vec::new(); - if Client.query("SELECT username, password FROM person WHERE password = $1", &[&Password])?.len() != 0 { - let Result = Client.query("SELECT username, password FROM person WHERE password = $1", &[&Password])?[0].clone(); - Response.push(Result.get(0)); - Response.push(Result.get(1)); - return Ok(Response); - } else { - return Ok(vec!["Password Not Correct.".to_string()]); - } - } else { - return Ok(vec!["Username Not Found.".to_string()]); - } -} - -pub fn GetAccountWithID(ID: i32) -> Result>{ - let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - - let Table = Client.query("SELECT 1 - FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_TYPE='BASE TABLE' - AND TABLE_NAME='person'", &[]); - // Check if the table doesn't exists. Or does? - match Table { - Ok(_) => { - // Check if the table exists. - if Table?.len() == 0 { - Client.batch_execute(" - CREATE TABLE person ( - id SERIAL PRIMARY KEY, - username TEXT NOT NULL, - password TEXT NOT NULL - )")?; - } - }, - Err(_) => () - } - let Result: String = Client.query("SELECT username FROM person WHERE id = $1", &[&ID]).unwrap()[0].get(0); - return Ok(Result.to_string()); -} - -pub fn MakeAccount(User: String, Pass: String) -> Result>{ - let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - - let Table = Client.query("SELECT 1 - FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_TYPE='BASE TABLE' - AND TABLE_NAME='person'", &[]); - // Check if the table doesn't exists. Or does? - match Table { - Ok(_) => { - // Check if the table exists. - if Table?.len() == 0 { - Client.batch_execute(" - CREATE TABLE person ( - id SERIAL PRIMARY KEY, - username TEXT NOT NULL, - password TEXT NOT NULL - )")?; - } - }, - Err(_) => () - } - Client.execute("INSERT INTO person (username, password) VALUES ($1, $2)", &[&User, &Pass])?; - return Ok("Account Created!".to_string()); -}