FromForm issue still there with /join route
Otherwise ready to integrate tests with auth module
This commit is contained in:
parent
220bc11ef0
commit
2f40da6c82
@ -1,13 +1,14 @@
|
|||||||
// Module handles creating invites for potentially new users
|
// Module handles creating invites for potentially new users
|
||||||
use diesel::{self, prelude::*};
|
use diesel::{self, prelude::*};
|
||||||
use rocket_contrib::json::Json;
|
use rocket_contrib::json::Json;
|
||||||
use rand::random;
|
use rocket::request::Form;
|
||||||
use crate::DBConn;
|
|
||||||
use crate::models::Invite;
|
|
||||||
use crate::schema;
|
|
||||||
use crate::users::new_user_response;
|
|
||||||
use crate::payload;
|
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
|
use rand::random;
|
||||||
|
|
||||||
|
use crate::auth::{join, JoinParams, AuthResult, AuthErr};
|
||||||
|
use crate::DBConn;
|
||||||
|
use crate::models::{User, Invite};
|
||||||
|
use crate::schema;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -44,37 +45,11 @@ pub fn generate_invite(conn: DBConn) -> Json<Invite> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<hash>")]
|
// TODO: `params` is non-payload-supporting somehow
|
||||||
pub fn use_invite(hash: u64, conn: DBConn) -> Json<payload::NewUserResponse> {
|
// NOTE: unted functions all the way down here
|
||||||
// Grab the token from our table to make sure it's even there to begin with
|
#[get("/<hash>", data = "<params>")]
|
||||||
use schema::invites::dsl::*;
|
pub fn use_invite(hash: u64, params: Form<JoinParams>, conn: DBConn) -> AuthResult<Json<User>, AuthErr>{
|
||||||
use schema::users::dsl::*;
|
join(conn, params, hash)
|
||||||
|
|
||||||
let diesel_result: Result<Invite, diesel::result::Error> = invites.filter(id.eq(hash)).first(&conn.0);
|
|
||||||
// TODO: this is getting moved elsewhere to clean up so ignore this for now
|
|
||||||
if let Ok(data) = diesel_result {
|
|
||||||
match data.uses {
|
|
||||||
1 ... std::i32::MAX => {
|
|
||||||
let user = crate::users::create_new_user();
|
|
||||||
match diesel::insert_into(users).values(&user).execute(&conn.0) {
|
|
||||||
Ok(_v) => Json(new_user_response(&Some(user), None)),
|
|
||||||
// an issue on our end gets a 500 response
|
|
||||||
Err(_e) => Json(new_user_response(&None, Some("Unable to create user")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The invite has been used up and thus should be removed
|
|
||||||
std::i32::MIN ... 0 => {
|
|
||||||
// bruh
|
|
||||||
let _ = diesel::delete(invites.filter(id.eq(data.id)))
|
|
||||||
.execute(&conn.0)
|
|
||||||
.expect("Could not delete invite");
|
|
||||||
Json(new_user_response(&None, Some("Invalid invite")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Json(new_user_response(&None, Some("Could not create user")))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user