From 869e7bc91be39dc4402c12c5af91f16a519df6aa Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sun, 4 Jun 2023 21:51:39 +0100 Subject: [PATCH] ferat: add new users to teh local db --- src/methods/account_new.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/methods/account_new.rs b/src/methods/account_new.rs index 40dde67..7079897 100644 --- a/src/methods/account_new.rs +++ b/src/methods/account_new.rs @@ -197,7 +197,7 @@ pub async fn post_new_account_confirmation(mut req: Request) -> tide::Res let AccountsPending{ user, mail, name_first, name_second, auth_code, expiry } = &results[0]; let dn = format!("uid={},ou=users,dc=skynet,dc=ie", user); - let uid_number = get_max_uid_number(db).await.to_string(); + let uid_number = get_max_uid_number(db).await; let home_directory = format!("/home/{}", user); let password_tmp = create_random_string(50); let cn = format!("{} {}", name_first, name_second); @@ -217,7 +217,7 @@ pub async fn post_new_account_confirmation(mut req: Request) -> tide::Res ("cn", HashSet::from([cn.as_str()])), // posixaccount - ("uidNumber", HashSet::from([uid_number.as_str()])), + ("uidNumber", HashSet::from([uid_number.to_string().as_str()])), ("gidNumber", HashSet::from(["1001"])), ("homedirectory", HashSet::from([home_directory.as_str()])), ("userpassword", HashSet::from([password_tmp.as_str()])), @@ -255,6 +255,21 @@ pub async fn post_new_account_confirmation(mut req: Request) -> tide::Res println!("{:?}", results) } + // add new users to teh local database + sqlx::query_as::<_, Accounts>( + " + INSERT OR REPLACE INTO accounts (user, uid_number, enabled) + VALUES (?1, ?2, ?3) + ", + ) + .bind(&user) + .bind(&uid_number) + .bind(false) + .fetch_optional(db) + .await + .ok(); + + // frontend tells user that initial password ahs been sent to tehm Ok(json!({"result": "success"}).into()) }