poc api code for generating invites
This commit is contained in:
parent
ecc08cc3f1
commit
4309f9890e
@ -1,19 +1,29 @@
|
|||||||
// Module handles creating invites for potentially new users
|
// Module handles creating invites for potentially new users
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Invite {
|
struct Invite {
|
||||||
hash: u64,
|
hash: u64,
|
||||||
uses: i32,
|
uses: i32,
|
||||||
expire: DateTime<Utc>,
|
expire: i64, // comes from a date time object ngl famalam
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/generate")]
|
#[get("/generate")]
|
||||||
pub fn generate_invite() -> String {
|
pub fn generate_invite() -> String {
|
||||||
format!("{:?}", Invite {
|
let dt = Utc::now() + Duration::minutes(30);
|
||||||
|
let invite = Invite {
|
||||||
hash: random::<u64>(),
|
hash: random::<u64>(),
|
||||||
uses: 1,
|
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("/<hash>")]
|
||||||
|
pub fn use_invite(hash: i64) -> String {
|
||||||
|
// check if the invite is somewhere in our invites table
|
||||||
|
format!("freechat.io/invite/{}", hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user