feat: now create teh pending user

This commit is contained in:
silver 2023-06-04 15:26:59 +01:00
parent 9c54a2f919
commit dcb4969b27
3 changed files with 48 additions and 0 deletions

1
Cargo.lock generated
View file

@ -1967,6 +1967,7 @@ dependencies = [
"async-std",
"dotenv",
"ldap3",
"rand 0.8.5",
"serde",
"sqlx",
"surf",

View file

@ -22,3 +22,6 @@ sqlx = { version = "0.6.3", features = [ "runtime-async-std-native-tls", "sqlite
# to make the http requests
surf = "2.3.2"
# create random strings
rand = "0.8.5"

View file

@ -97,6 +97,39 @@ pub async fn post_new_account(mut req: Request<State>) -> tide::Result {
}
}
// frontend now tells user to check their email
/*
TODO:
now check with wolves to see if the email is already activated
use email as primary match
then search up to see if teh wolves ID has a match
if not generate tuhe user and send email
*/
let auth_code = create_random_string(50);
// 1 hour expiry
let expiry = get_now() + (60 * 60);
sqlx::query_as::<_, AccountsPending>(
r#"
INSERT OR REPLACE INTO accounts_pending (user, mail, name_first, name_second, auth_code, discord, expiry)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)
"#,
)
.bind(&user)
.bind(&mail)
.bind(&name_first)
.bind(&name_second)
.bind(&auth_code)
.bind(&discord)
.bind(&expiry)
.fetch_optional(pool)
.await
.ok();
// TODO: Send email with auth_code
Ok(json!({"result": "success"}).into())
}
@ -115,3 +148,14 @@ async fn db_pending_clear_expired(pool: &Pool<Sqlite>){
println!("{:?}", results)
}
}
fn create_random_string(length: usize) -> String {
use rand::{thread_rng, Rng};
use rand::distributions::Alphanumeric;
thread_rng()
.sample_iter(&Alphanumeric)
.take(length)
.map(char::from)
.collect()
}