fix: removed some unused database attributes

This commit is contained in:
silver 2023-10-26 00:45:14 +01:00
parent 20d79e427a
commit 5267c588c4
2 changed files with 2 additions and 19 deletions

View file

@ -58,10 +58,8 @@ async fn update_ldap(config: &Config, db: &Pool<Sqlite>) {
let mut tmp_account = Accounts { let mut tmp_account = Accounts {
user: "".to_string(), user: "".to_string(),
uid: 0, uid: 0,
discord: None,
mail: "".to_string(), mail: "".to_string(),
student_id: "".to_string(), student_id: "".to_string(),
enabled: false,
secure: false, secure: false,
}; };
@ -72,21 +70,12 @@ async fn update_ldap(config: &Config, db: &Pool<Sqlite>) {
if tmp.attrs.contains_key("uidNumber") && !tmp.attrs["uidNumber"].is_empty() { if tmp.attrs.contains_key("uidNumber") && !tmp.attrs["uidNumber"].is_empty() {
tmp_account.uid = tmp.attrs["uidNumber"][0].clone().parse().unwrap_or(0); tmp_account.uid = tmp.attrs["uidNumber"][0].clone().parse().unwrap_or(0);
} }
if tmp.attrs.contains_key("skDiscord") && !tmp.attrs["skDiscord"].is_empty() {
tmp_account.discord = Option::from(tmp.attrs["skDiscord"][0].clone());
}
if tmp.attrs.contains_key("mail") && !tmp.attrs["mail"].is_empty() { if tmp.attrs.contains_key("mail") && !tmp.attrs["mail"].is_empty() {
tmp_account.mail = tmp.attrs["mail"][0].clone(); tmp_account.mail = tmp.attrs["mail"][0].clone();
} }
if tmp.attrs.contains_key("skID") && !tmp.attrs["skID"].is_empty() { if tmp.attrs.contains_key("skID") && !tmp.attrs["skID"].is_empty() {
tmp_account.student_id = tmp.attrs["skID"][0].clone(); tmp_account.student_id = tmp.attrs["skID"][0].clone();
} }
if tmp.attrs.contains_key("skMemberOf")
&& !tmp.attrs["skMemberOf"].is_empty()
&& tmp.attrs["skMemberOf"].contains(&String::from("cn=skynet-users-linux,ou=groups,dc=skynet,dc=ie"))
{
tmp_account.enabled = true;
}
if tmp.attrs.contains_key("userPassword") && !tmp.attrs["userPassword"].is_empty() { if tmp.attrs.contains_key("userPassword") && !tmp.attrs["userPassword"].is_empty() {
tmp_account.secure = tmp.attrs["userPassword"][0].starts_with("{SSHA512}") tmp_account.secure = tmp.attrs["userPassword"][0].starts_with("{SSHA512}")
} }
@ -94,16 +83,14 @@ async fn update_ldap(config: &Config, db: &Pool<Sqlite>) {
if !tmp_account.user.is_empty() { if !tmp_account.user.is_empty() {
sqlx::query_as::<_, Accounts>( sqlx::query_as::<_, Accounts>(
" "
INSERT OR REPLACE INTO accounts (user, uid, discord, mail, student_id, enabled, secure) INSERT OR REPLACE INTO accounts (user, uid, mail, student_id, secure)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7) VALUES (?1, ?2, ?3, ?4, ?5)
", ",
) )
.bind(&tmp_account.user) .bind(&tmp_account.user)
.bind(tmp_account.uid) .bind(tmp_account.uid)
.bind(&tmp_account.discord)
.bind(&tmp_account.mail) .bind(&tmp_account.mail)
.bind(&tmp_account.student_id) .bind(&tmp_account.student_id)
.bind(tmp_account.enabled)
.bind(tmp_account.secure) .bind(tmp_account.secure)
.fetch_optional(db) .fetch_optional(db)
.await .await

View file

@ -54,10 +54,8 @@ pub struct AccountsSSH {
pub struct Accounts { pub struct Accounts {
pub user: String, pub user: String,
pub uid: i64, pub uid: i64,
pub discord: Option<String>,
pub mail: String, pub mail: String,
pub student_id: String, pub student_id: String,
pub enabled: bool,
pub secure: bool, pub secure: bool,
} }
@ -135,10 +133,8 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
"CREATE TABLE IF NOT EXISTS accounts ( "CREATE TABLE IF NOT EXISTS accounts (
user text PRIMARY KEY, user text PRIMARY KEY,
uid integer NOT NULL, uid integer NOT NULL,
discord text,
mail text NOT NULL, mail text NOT NULL,
student_id text NOT NULL, student_id text NOT NULL,
enabled integer NOT NULL,
secure integer NOT NULL secure integer NOT NULL
)", )",
) )