Invite are now consumed via a path with two dynamic params
/invite/join/<hash>/<name> is the real path to be used now but the app ui should this behavior in some clever way
This commit is contained in:
		
							parent
							
								
									2f40da6c82
								
							
						
					
					
						commit
						81e6fd0a13
					
				| @ -56,7 +56,7 @@ impl<'r> Responder<'r> for AuthErr { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| pub fn join(conn: DBConn, params: Form<JoinParams>, hashcode: u64) -> AuthResult<Json<User>, AuthErr>{ | pub fn join(conn: DBConn, hashcode: u64, name: String) -> AuthResult<Json<User>, AuthErr>{ | ||||||
|     /* |     /* | ||||||
|      * Requires <code:int> -> body |      * Requires <code:int> -> body | ||||||
|      * Requires <name:string> -> body |      * Requires <name:string> -> body | ||||||
| @ -68,13 +68,13 @@ pub fn join(conn: DBConn, params: Form<JoinParams>, hashcode: u64) -> AuthResult | |||||||
|     const negate: &'static str = "Malformed request"; |     const negate: &'static str = "Malformed request"; | ||||||
| 
 | 
 | ||||||
|     let diesel_result: Result<Invite, diesel::result::Error> = invites |     let diesel_result: Result<Invite, diesel::result::Error> = invites | ||||||
|         .filter(invites::dsl::id.eq(params.code)) |         .filter(invites::dsl::id.eq(hashcode)) | ||||||
|         .first(&conn.0); |         .first(&conn.0); | ||||||
| 
 | 
 | ||||||
|     if let Ok(data) = diesel_result { |     if let Ok(data) = diesel_result { | ||||||
|         match data.uses { |         match data.uses { | ||||||
|             1 ..= std::i32::MAX => { |             1 ..= std::i32::MAX => { | ||||||
|                 let new_user = crate::users::create_new_user(conn, params.name); |                 let new_user = crate::users::create_new_user(conn, name); | ||||||
|                 // update the uses counter
 |                 // update the uses counter
 | ||||||
|                 let _ignored = diesel::update(invites.filter(invites::dsl::id.eq(hashcode))) |                 let _ignored = diesel::update(invites.filter(invites::dsl::id.eq(hashcode))) | ||||||
|                     .set(uses.eq(data.uses - 1)) |                     .set(uses.eq(data.uses - 1)) | ||||||
|  | |||||||
| @ -1,11 +1,10 @@ | |||||||
| // 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 rocket::request::Form; |  | ||||||
| use chrono::{Duration, Utc}; | use chrono::{Duration, Utc}; | ||||||
| use rand::random; | use rand::random; | ||||||
| 
 | 
 | ||||||
| use crate::auth::{join, JoinParams, AuthResult, AuthErr}; | use crate::auth::{join, AuthResult, AuthErr}; | ||||||
| use crate::DBConn; | use crate::DBConn; | ||||||
| use crate::models::{User, Invite}; | use crate::models::{User, Invite}; | ||||||
| use crate::schema; | use crate::schema; | ||||||
| @ -45,11 +44,11 @@ pub fn generate_invite(conn: DBConn) -> Json<Invite> { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // TODO: `params` is non-payload-supporting somehow
 | // GET doesn't really like having data in its body for whatever reason
 | ||||||
| // NOTE: unted functions all the way down here
 | // Problem: invite/joining system is gonna have to get a redesign
 | ||||||
| #[get("/<hash>", data = "<params>")] | #[get("/join/<hash>/<name>")] | ||||||
| pub fn use_invite(hash: u64, params: Form<JoinParams>, conn: DBConn) ->  AuthResult<Json<User>, AuthErr>{ | pub fn use_invite(hash: u64, name: String, conn: DBConn) ->  AuthResult<Json<User>, AuthErr>{ | ||||||
|     join(conn, params, hash) |     join(conn, hash, name) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 shockrah
						shockrah