From 542d23d7c7f6a9f8586ac1fcef65b7cc58b91a81 Mon Sep 17 00:00:00 2001 From: reidlab Date: Sun, 3 Sep 2023 16:21:24 -0700 Subject: [PATCH] formatting changes --- readme.md | 1 + src/endpoints/accounts/login_account.rs | 15 +++++++++------ src/endpoints/accounts/register_account.rs | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 4a42832..9f66f88 100644 --- a/readme.md +++ b/readme.md @@ -34,6 +34,7 @@ _these features are implemented_ ## todo +- when gjp2 is finally dropped we should 100% swap so it works in two point two - green name users (fuck green names!!) - move authorization logic to (./src/helpers/accounts.rs)[./src/helpers/accounts.rs] - 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/accounts/login_account.rs b/src/endpoints/accounts/login_account.rs index f84fa50..0fc70b4 100644 --- a/src/endpoints/accounts/login_account.rs +++ b/src/endpoints/accounts/login_account.rs @@ -34,18 +34,21 @@ pub fn login_account(input: Form) -> status::Custom<&'static s { use crate::schema::accounts::dsl::*; - let account_id_password_result = accounts + let query_result = accounts .select((id, password)) .filter(username.eq(input.userName.clone())) .get_result::<(i32, String)>(connection); - match account_id_password_result { - Ok(account_id_password) => { - let user_id = helpers::accounts::get_user_id_from_account_id(account_id_password.0); + match query_result { + Ok(( + account_id_val, + password_val + )) => { + let user_id = helpers::accounts::get_user_id_from_account_id(account_id_val); - match verify_password(input.password.clone().as_bytes(), account_id_password.1.as_str()) { + match verify_password(input.password.clone().as_bytes(), password_val.as_str()) { Ok(_) => return status::Custom(Status::Ok, - Box::leak(format!("{},{}", account_id_password.0, user_id).into_boxed_str()) + Box::leak(format!("{},{}", account_id_val, user_id).into_boxed_str()) ), Err(_) => return status::Custom(Status::Ok, "-11") }; diff --git a/src/endpoints/accounts/register_account.rs b/src/endpoints/accounts/register_account.rs index c754a52..92c02f5 100644 --- a/src/endpoints/accounts/register_account.rs +++ b/src/endpoints/accounts/register_account.rs @@ -66,6 +66,7 @@ pub fn register_account(input: Form) -> status::Custom<&'st gjp2: generate_hash(helpers::encryption::get_gjp2(input.password.clone())), email: input.email.clone() }; + inserted_account = diesel::insert_into(accounts) .values(&new_account) .get_result::(connection) @@ -83,6 +84,7 @@ pub fn register_account(input: Form) -> status::Custom<&'st username: input.userName.clone(), registered: 1 }; + diesel::insert_into(users) .values(&new_user) .get_result::(connection)