Compare commits
4 commits
11f89a2380
...
bda9f85b86
Author | SHA1 | Date | |
---|---|---|---|
bda9f85b86 | |||
799a1ff49e | |||
0f1824b366 | |||
1f897deb33 |
4 changed files with 60 additions and 47 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -20,3 +20,4 @@ Cargo.lock
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
/config.toml
|
||||||
|
|
|
@ -93,17 +93,14 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(match data.pool.execute(
|
// TODO: Check security of this implementation
|
||||||
&*format!(
|
Ok(match sqlx::query(&format!("INSERT INTO users VALUES ( '{}', $1, NULL, $2, $3, false )", uuid))
|
||||||
// FIXME: This can never be put into prod, it works for testing
|
.bind(account_information.identifier)
|
||||||
"INSERT INTO users VALUES ( '{}', '{}', NULL, '{}', '{}', '0' )",
|
|
||||||
uuid,
|
|
||||||
account_information.identifier,
|
|
||||||
// FIXME: Password has no security currently, either from a client or server perspective
|
// FIXME: Password has no security currently, either from a client or server perspective
|
||||||
account_information.password,
|
.bind(account_information.password)
|
||||||
account_information.email,
|
.bind(account_information.email)
|
||||||
)
|
.execute(&data.pool)
|
||||||
).await {
|
.await {
|
||||||
Ok(_out) => {
|
Ok(_out) => {
|
||||||
HttpResponse::Ok().json(
|
HttpResponse::Ok().json(
|
||||||
Response {
|
Response {
|
||||||
|
@ -126,9 +123,10 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
email_available: false,
|
email_available: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
_ => HttpResponse::Forbidden().json(ResponseError {
|
_ => {
|
||||||
..Default::default()
|
eprintln!("{}", err_msg);
|
||||||
})
|
HttpResponse::InternalServerError().finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,9 +17,16 @@ struct Response {
|
||||||
|
|
||||||
#[get("/stats")]
|
#[get("/stats")]
|
||||||
pub async fn res(data: web::Data<Data>) -> impl Responder {
|
pub async fn res(data: web::Data<Data>) -> impl Responder {
|
||||||
|
let accounts;
|
||||||
|
if let Ok(users) = sqlx::query("SELECT uuid FROM users").fetch_all(&data.pool).await {
|
||||||
|
accounts = users.len();
|
||||||
|
} else {
|
||||||
|
return HttpResponse::InternalServerError().finish()
|
||||||
|
}
|
||||||
|
|
||||||
let response = Response {
|
let response = Response {
|
||||||
// TODO: Get number of accounts from db
|
// TODO: Get number of accounts from db
|
||||||
accounts: 0,
|
accounts,
|
||||||
uptime: SystemTime::now()
|
uptime: SystemTime::now()
|
||||||
.duration_since(data.start_time)
|
.duration_since(data.start_time)
|
||||||
.expect("Seriously why dont you have time??")
|
.expect("Seriously why dont you have time??")
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -26,15 +26,22 @@ async fn main() -> Result<(), Error> {
|
||||||
TODO: Figure out if a table should be used here and if not then what.
|
TODO: Figure out if a table should be used here and if not then what.
|
||||||
Also figure out if these should be different types from what they currently are and if we should add more "constraints"
|
Also figure out if these should be different types from what they currently are and if we should add more "constraints"
|
||||||
*/
|
*/
|
||||||
pool.execute(r#"CREATE TABLE IF NOT EXISTS users (
|
sqlx::raw_sql(r#"
|
||||||
uuid uuid UNIQUE NOT NULL,
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
uuid uuid PRIMARY KEY UNIQUE NOT NULL,
|
||||||
username varchar(32) UNIQUE NOT NULL,
|
username varchar(32) UNIQUE NOT NULL,
|
||||||
display_name varchar(64),
|
display_name varchar(64),
|
||||||
password varchar(512) NOT NULL,
|
password varchar(512) NOT NULL,
|
||||||
email varchar(100) UNIQUE NOT NULL,
|
email varchar(100) UNIQUE NOT NULL,
|
||||||
email_verified integer NOT NULL DEFAULT '0',
|
email_verified boolean NOT NULL DEFAULT FALSE
|
||||||
PRIMARY KEY (uuid)
|
);
|
||||||
)"#).await?;
|
CREATE TABLE IF NOT EXISTS instance_permissions (
|
||||||
|
uuid uuid REFERENCES users(uuid),
|
||||||
|
administrator boolean NOT NULL DEFAULT FALSE
|
||||||
|
)
|
||||||
|
"#)
|
||||||
|
.execute(&pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let data = Data {
|
let data = Data {
|
||||||
pool,
|
pool,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue