Fixing /join route, time check was backwards oops and it was set to GET not post
This commit is contained in:
parent
ab1c9e40f7
commit
212173f543
@ -11,7 +11,7 @@ use crate::common::FromDB;
|
|||||||
use crate::{Response, no_conn};
|
use crate::{Response, no_conn};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, Debug)]
|
||||||
pub struct Invite {
|
pub struct Invite {
|
||||||
pub id: BigInt,
|
pub id: BigInt,
|
||||||
pub uses: Option<BigInt>,
|
pub uses: Option<BigInt>,
|
||||||
|
@ -16,6 +16,7 @@ pub type UInteger = u32;
|
|||||||
|
|
||||||
pub type VarChar = String;
|
pub type VarChar = String;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Response<T> {
|
pub enum Response<T> {
|
||||||
// A set of rows collected
|
// A set of rows collected
|
||||||
Set(Vec<T>),
|
Set(Vec<T>),
|
||||||
|
@ -16,6 +16,7 @@ use db::invites::Invite;
|
|||||||
|
|
||||||
use crate::qs_param;
|
use crate::qs_param;
|
||||||
use crate::http;
|
use crate::http;
|
||||||
|
use crate::meta;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -38,7 +39,8 @@ async fn valid_invite(pool: &Pool, id: BigInt) -> bool {
|
|||||||
if invite.expires {
|
if invite.expires {
|
||||||
let now = Utc::now().timestamp();
|
let now = Utc::now().timestamp();
|
||||||
// old?
|
// old?
|
||||||
let mut valid_status = now > invite.id;
|
println!("{} {}", now, invite.id);
|
||||||
|
let mut valid_status = now < invite.id;
|
||||||
// used?
|
// used?
|
||||||
if invite.uses.is_some() && valid_status == false {
|
if invite.uses.is_some() && valid_status == false {
|
||||||
valid_status = invite.uses.unwrap() <= 0; // safe unwrap since we know its Some(_)
|
valid_status = invite.uses.unwrap() <= 0; // safe unwrap since we know its Some(_)
|
||||||
@ -68,27 +70,21 @@ async fn use_invite(pool: &Pool, code: Option<BigInt>) -> Option<Member>{
|
|||||||
// some random comment
|
// some random comment
|
||||||
if valid_invite(pool, id).await {
|
if valid_invite(pool, id).await {
|
||||||
let raw_secret = auth::generate_secret();
|
let raw_secret = auth::generate_secret();
|
||||||
if let Ok(secret) = auth::encrypt_secret(&raw_secret) {
|
let secret = auth::encrypt_secret(&raw_secret).unwrap();
|
||||||
return match db::member::Member::add(pool, "Anonymous".into(), &secret, GENERAL_NEW).await {
|
return match db::member::Member::add(pool, "Anonymous".into(), &secret, GENERAL_NEW).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response {
|
match response {
|
||||||
db::Response::Row(member) => Some(member),
|
db::Response::Row(member) => Some(member),
|
||||||
_ => None,
|
_ => None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// TODO: logggin or something idk
|
// TODO: logggin or something idk
|
||||||
Err(_) => return None
|
Err(_) => None
|
||||||
}
|
|
||||||
}
|
|
||||||
// Returning None because we couldn't actually create a proper secret to store
|
|
||||||
else {
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The invite itself was not valid
|
// The invite itself was not valid
|
||||||
else {
|
// Returning None because we couldn't actually create a proper secret to store
|
||||||
return None;
|
return None;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn join(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
pub async fn join(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||||
@ -112,7 +108,10 @@ pub async fn join(pool: &Pool, response: &mut Response<Body>, params: HashMap<St
|
|||||||
// Returns a new member if the code is used successfully
|
// Returns a new member if the code is used successfully
|
||||||
match use_invite(&pool, code).await {
|
match use_invite(&pool, code).await {
|
||||||
Some(new_account) => {
|
Some(new_account) => {
|
||||||
http::set_json_body(response, json!(new_account))
|
http::set_json_body(response, json!({
|
||||||
|
"user": new_account,
|
||||||
|
"server": meta::get_config()
|
||||||
|
}))
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
*response.status_mut() = StatusCode::NOT_FOUND;
|
*response.status_mut() = StatusCode::NOT_FOUND;
|
||||||
|
@ -58,7 +58,7 @@ async fn route_dispatcher(
|
|||||||
const DELETE: &Method = &Method::DELETE;
|
const DELETE: &Method = &Method::DELETE;
|
||||||
match (meth, path) {
|
match (meth, path) {
|
||||||
/* INVITES */
|
/* INVITES */
|
||||||
(GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await,
|
(POST, routes::INVITE_CREATE) => invites::create(pool, resp, params).await,
|
||||||
(GET, routes::INVITE_JOIN) => invites::join(pool, resp, params).await,
|
(GET, routes::INVITE_JOIN) => invites::join(pool, resp, params).await,
|
||||||
/* CHANNELS */
|
/* CHANNELS */
|
||||||
(GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await,
|
(GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await,
|
||||||
|
Loading…
Reference in New Issue
Block a user