Delete src/API/mod.rs
This commit is contained in:
parent
26ae559037
commit
949cf74a31
1 changed files with 0 additions and 90 deletions
|
@ -1,90 +0,0 @@
|
|||
use postgres::{Client, NoTls};
|
||||
|
||||
pub fn Login(Username: &str, Password: &str) -> Result<Vec<String>, Box<dyn std::error::Error>>{
|
||||
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<String> = 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<String, Box<dyn std::error::Error>>{
|
||||
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<String, Box<dyn std::error::Error>>{
|
||||
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());
|
||||
}
|
Loading…
Add table
Reference in a new issue