feat: small little function to get the next user id
This commit is contained in:
parent
b9fdde4033
commit
5b6195db31
1 changed files with 21 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{AccountsPending, get_now, State};
|
||||
use crate::{Accounts, AccountsPending, get_now, State};
|
||||
use ldap3::exop::PasswordModify;
|
||||
use ldap3::{LdapConn, Mod, Scope, SearchEntry};
|
||||
use std::collections::HashSet;
|
||||
|
@ -178,7 +178,7 @@ pub async fn post_new_account_confirmation(mut req: Request<State>) -> tide::Res
|
|||
} = &req.state();
|
||||
|
||||
// make sure to clear out the expired ones first
|
||||
db_pending_clear_expired(db).await;
|
||||
//db_pending_clear_expired(db).await;
|
||||
|
||||
// search db for auth_code
|
||||
let results = sqlx::query_as::<_, AccountsPending>(
|
||||
|
@ -200,8 +200,7 @@ pub async fn post_new_account_confirmation(mut req: Request<State>) -> tide::Res
|
|||
|
||||
let AccountsPending{ user, mail, name_first, name_second, auth_code, discord, expiry } = &results[0];
|
||||
let dn = format!("uid={},ou=users,dc=skynet,dc=ie", user);
|
||||
// TODO: find highrest uid number
|
||||
let uid_number = "9990";
|
||||
let uid_number = get_max_uid_number(db).await.to_string();
|
||||
let home_directory = format!("/home/{}", user);
|
||||
let password_tmp = create_random_string(50);
|
||||
let cn = format!("{} {}", name_first, name_second);
|
||||
|
@ -221,7 +220,7 @@ pub async fn post_new_account_confirmation(mut req: Request<State>) -> tide::Res
|
|||
("cn", HashSet::from([cn.as_str()])),
|
||||
|
||||
// posixaccount
|
||||
("uidNumber", HashSet::from([uid_number])),
|
||||
("uidNumber", HashSet::from([uid_number.as_str()])),
|
||||
("gidNumber", HashSet::from(["1001"])),
|
||||
("homedirectory", HashSet::from([home_directory.as_str()])),
|
||||
("userpassword", HashSet::from([password_tmp.as_str()])),
|
||||
|
@ -269,3 +268,20 @@ fn get_sk_created() -> String {
|
|||
|
||||
format!("{}", now.format("%Y%m%d%H%M%SZ"))
|
||||
}
|
||||
|
||||
pub async fn get_max_uid_number(db: &Pool<Sqlite>) -> i64 {
|
||||
if let Ok(results) = sqlx::query_as::<_, Accounts>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM accounts
|
||||
ORDER BY uid_number DESC
|
||||
LIMIT 1
|
||||
"#,
|
||||
).fetch_all(db).await {
|
||||
if !results.is_empty() {
|
||||
return results[0].uid_number + 1;
|
||||
}
|
||||
}
|
||||
|
||||
9999
|
||||
}
|
Loading…
Reference in a new issue