diff --git a/server/src/invites.rs b/server/src/invites.rs index 29f3899..ab90946 100644 --- a/server/src/invites.rs +++ b/server/src/invites.rs @@ -1,19 +1,29 @@ // Module handles creating invites for potentially new users use rand::random; -use chrono::{DateTime, Duration, Utc}; +use chrono::{Duration, Utc}; #[derive(Debug)] struct Invite { hash: u64, uses: i32, - expire: DateTime, + expire: i64, // comes from a date time object ngl famalam } #[get("/generate")] pub fn generate_invite() -> String { - format!("{:?}", Invite { + let dt = Utc::now() + Duration::minutes(30); + let invite = Invite { hash: random::(), uses: 1, - expire: Utc::now() + Duration::minutes(30), - }) + expire: dt.timestamp(), + }; + // Insert the new invite into our database + format!("freechat.io/invite/{}", invite.hash) } + +#[get("/")] +pub fn use_invite(hash: i64) -> String { + // check if the invite is somewhere in our invites table + format!("freechat.io/invite/{}", hash) +} +