feat: backport changes from the #17-automate-onboarding-mk-ii branch
Some checks failed
On_Push / lint_fmt (push) Failing after 38s
On_Push / lint_clippy (push) Failing after 38s
On_Push / build (push) Has been skipped
On_Push / deploy (push) Has been skipped

This commit is contained in:
silver 2024-11-23 22:17:57 +00:00
parent 93359698f0
commit 37ea38f516
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
4 changed files with 433 additions and 96 deletions

View file

@ -59,7 +59,34 @@ pub mod link {
// check if email exists
let details = match get_server_member_email(&db, email).await {
None => {
return "Please check it matches (including case) your preferred contact on https://ulwolves.ie/memberships/profile and that you are fully paid up.".to_string()
let invalid_user = "Please check it matches (including case) your preferred contact on https://ulwolves.ie/memberships/profile and that you are fully paid up.".to_string();
let wolves = wolves_oxidised::Client::new(&config.wolves_url, Some(&config.wolves_api));
// see if the user actually exists
let id = match wolves.get_member(email).await {
None => {
return invalid_user;
}
Some(x) => x,
};
// save teh user id and email to teh db
match save_to_db_user(&db, id, email).await {
Ok(x) => x,
Err(x) => {
dbg!(x);
return "Error: unable to save user to teh database, contact Computer Society".to_string();
}
};
// pull it back out (technically could do it in previous step but more explicit)
match get_server_member_email(&db, email).await {
None => {
return "Error: failed to read user from database.".to_string();
}
Some(x) => x,
}
}
Some(x) => x,
};
@ -232,6 +259,20 @@ pub mod link {
.fetch_optional(db)
.await
}
async fn save_to_db_user(db: &Pool<Sqlite>, id_wolves: i64, email: &str) -> Result<Option<Wolves>, sqlx::Error> {
sqlx::query_as::<_, Wolves>(
"
INSERT INTO wolves (id_wolves, email)
VALUES ($1, $2)
ON CONFLICT(id_wolves) DO UPDATE SET email = $2
",
)
.bind(id_wolves)
.bind(email)
.fetch_optional(db)
.await
}
}
pub mod verify {