ferat: add new users to teh local db

This commit is contained in:
silver 2023-06-04 21:51:39 +01:00
parent 36b13fb1f2
commit 869e7bc91b

View file

@ -197,7 +197,7 @@ pub async fn post_new_account_confirmation(mut req: Request<State>) -> tide::Res
let AccountsPending{ user, mail, name_first, name_second, auth_code, expiry } = &results[0]; 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 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 home_directory = format!("/home/{}", user);
let password_tmp = create_random_string(50); let password_tmp = create_random_string(50);
let cn = format!("{} {}", name_first, name_second); let cn = format!("{} {}", name_first, name_second);
@ -217,7 +217,7 @@ pub async fn post_new_account_confirmation(mut req: Request<State>) -> tide::Res
("cn", HashSet::from([cn.as_str()])), ("cn", HashSet::from([cn.as_str()])),
// posixaccount // posixaccount
("uidNumber", HashSet::from([uid_number.as_str()])), ("uidNumber", HashSet::from([uid_number.to_string().as_str()])),
("gidNumber", HashSet::from(["1001"])), ("gidNumber", HashSet::from(["1001"])),
("homedirectory", HashSet::from([home_directory.as_str()])), ("homedirectory", HashSet::from([home_directory.as_str()])),
("userpassword", HashSet::from([password_tmp.as_str()])), ("userpassword", HashSet::from([password_tmp.as_str()])),
@ -255,6 +255,21 @@ pub async fn post_new_account_confirmation(mut req: Request<State>) -> tide::Res
println!("{:?}", results) 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 // frontend tells user that initial password ahs been sent to tehm
Ok(json!({"result": "success"}).into()) Ok(json!({"result": "success"}).into())
} }