From 66489506ac24348edcfd697ed251aa9a61176426 Mon Sep 17 00:00:00 2001 From: reidlab Date: Mon, 4 Sep 2023 03:41:32 -0700 Subject: [PATCH] more level boilerplate --- readme.md | 4 +- src/endpoints/levels/upload_level.rs | 73 +++++++++++----------------- src/main.rs | 4 +- 3 files changed, 34 insertions(+), 47 deletions(-) diff --git a/readme.md b/readme.md index afe0efa..9d7eb6f 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ _these features are implemented_ ## todo -- clean auth function (wtf is that!) -- add udid auth to auth function +- probably work on the code warnings we get hehe +- green name users... (add udid auth to auth function, use userName instead of accountID in uploading levels, and it goes on and on and on and on...) - add level parsing - maybe swap to timestamp type instead of `(TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.MS'))` (thats REALLY ugly!!) \ No newline at end of file diff --git a/src/endpoints/levels/upload_level.rs b/src/endpoints/levels/upload_level.rs index f254bc1..2444bca 100644 --- a/src/endpoints/levels/upload_level.rs +++ b/src/endpoints/levels/upload_level.rs @@ -1,51 +1,36 @@ -// use password_auth::verify_password; -// use rocket::form::Form; -// use rocket::http::Status; -// use rocket::response::status; +use password_auth::verify_password; +use rocket::form::Form; +use rocket::http::Status; +use rocket::response::status; -// use diesel::prelude::*; +use diesel::prelude::*; -// use crate::helpers; -// use crate::db; +use crate::helpers; +use crate::db; -// #[derive(FromForm)] -// pub struct FromLoginAccount { -// accountID: i32, -// gjp: String -// } - -// #[post("/accounts/loginGJAccount.php", data = "")] -// pub fn login_account(input: Form) -> status::Custom<&'static str> { -// let connection = &mut db::establish_connection_pg(); +#[derive(FromForm)] +pub struct FormUploadLevel { + accountID: i32, -// // account verification -// let (user_id, account_id): (i32, i32); + password: Option, + gjp: Option, + gjp2: Option, +} -// { -// use crate::schema::accounts::dsl::*; +#[post("/uploadGJLevel21.php", data = "")] +pub fn upload_level(input: Form) -> status::Custom<&'static str> { + let connection = &mut db::establish_connection_pg(); -// let query_result = accounts -// .select((id, password)) -// .filter(username.eq(input.userName.clone())) -// .get_result::<(i32, String)>(connection); - -// match query_result { -// Ok(( -// account_id_val, -// password_val -// )) => { -// user_id = helpers::accounts::get_user_id_from_account_id(account_id_val); - -// match verify_password(input.password.clone().as_bytes(), password_val.as_str()) { -// Ok(_) => return status::Custom(Status::Ok, -// Box::leak(format!("{},{}", account_id_val, user_id).into_boxed_str()) -// ), -// Err(_) => return status::Custom(Status::Ok, "-11") -// }; -// }, -// Err(_) => return status::Custom(Status::Ok, "-1") -// } -// } + // account verification + let (user_id_val, account_id_val): (i32, i32); -// return status::Custom(Status::Ok, "1") -// } \ No newline at end of file + match helpers::accounts::auth(input.accountID.clone(), input.password.clone(), input.gjp.clone(), input.gjp2.clone()) { + Ok((user_id, account_id)) => { + user_id_val = user_id; + account_id_val = account_id; + }, + Err(_) => return status::Custom(Status::Ok, "-1") + }; + + return status::Custom(Status::Ok, "1") +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bc0551e..6c30eb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,8 @@ fn rocket() -> _ { endpoints::accounts::login_account::login_account, endpoints::accounts::register_account::register_account, - endpoints::users::get_users::get_users + endpoints::users::get_users::get_users, + + endpoints::levels::upload_level::upload_level ]) } \ No newline at end of file