From 1c1bb5f3cd991f7a88c7bee2fc3869217462701b Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 21 Nov 2020 13:21:44 -0800 Subject: [PATCH] * -c now uses the name parameter given to it * new branch for failure of secret generation --- server-api/src/main.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/server-api/src/main.rs b/server-api/src/main.rs index c79a3ac..15e048f 100644 --- a/server-api/src/main.rs +++ b/server-api/src/main.rs @@ -211,21 +211,26 @@ OPTIONS: let owner_secret = auth::generate_secret(); // creation of owner should just dump straight to stdout since this fires // from a commandline parameter anyway - match db::member::Member::add(&p, "owner sama uwu", &owner_secret, perms::OWNER).await { - Ok(response) => { - match response { - db::Response::Row(owner) => - println!("{}", serde_json::to_string(&owner).expect("SQL query passed but serde couldn't parse the data for some reason")), - db::Response::Empty => { - eprintln!("SQL server failed to return owner data, check configs and also the members table to make sure there's nothing there by accident"); - }, - _ => {} - }; - }, - Err(_) => { - eprintln!("Could not communicate with the SQL server, check your configs!"); + if let Ok(enc_secret) = auth::encrypt_secret(&owner_secret) { + match db::member::Member::add(&p, owner_name, &enc_secret, perms::OWNER).await { + Ok(response) => { + match response { + db::Response::Row(owner) => + println!("{}", serde_json::to_string(&owner).expect("SQL query passed but serde couldn't parse the data for some reason")), + db::Response::Empty => { + eprintln!("SQL server failed to return owner data, check configs and also the members table to make sure there's nothing there by accident"); + }, + _ => {} + }; + }, + Err(_) => { + eprintln!("Could not communicate with the SQL server, check your configs!"); + } } } + else { + eprintln!("Could not generate a proper secret"); + } //println!("{}", serde_json::to_string(&owner).unwrap()); p.disconnect(); }