@ -62,11 +62,12 @@ struct KeysData { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					#[ post( " /accounts/register " , data =  " <data> " ) ]  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					fn  register ( data : JsonUpcase < RegisterData > ,   conn : DbConn )   -> EmptyResult   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     let   data : RegisterData   =   data . into_inner ( ) . data ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     let   email   =   data . Email . to_lowercase ( ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     let   mut   user   =   match   User ::find_by_mail ( & data . E mail,   & conn )   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     let   mut   user   =   match   User ::find_by_mail ( & e mail,   & conn )   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					         Some ( user )   = >   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             if   ! user . password_hash . is_empty ( )   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 if   CONFIG . is_signup_allowed ( & data . E mail)   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 if   CONFIG . is_signup_allowed ( & e mail)   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                     err ! ( "User already exists" )  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 }   else   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                     err ! ( "Registration not allowed or user already exists" )  
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				
					@ -75,19 +76,19 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             if   let   Some ( token )   =   data . Token   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 let   claims   =   decode_invite ( & token ) ? ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 if   claims . email   = =   data . E mail  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 if   claims . email   = =   e mail  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                     user  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 }   else   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                     err ! ( "Registration email does not match invite email" )  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 }  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }   else   if   Invitation ::take ( & data . E mail,   & conn )   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }   else   if   Invitation ::take ( & e mail,   & conn )   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 for   mut   user_org   in   UserOrganization ::find_invited_by_user ( & user . uuid ,   & conn ) . iter_mut ( )   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                     user_org . status   =   UserOrgStatus ::Accepted   as   i32 ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                     user_org . save ( & conn ) ? ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 }  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 user  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }   else   if   CONFIG . is_signup_allowed ( & data . E mail)   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }   else   if   CONFIG . is_signup_allowed ( & e mail)   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 err ! ( "Account with this email already exists" )  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }   else   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 err ! ( "Registration not allowed or user already exists" )  
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				
					@ -97,8 +98,8 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             // Order is important here; the invitation check must come first
  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             // because the vaultwarden admin can invite anyone, regardless
  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             // of other signup restrictions.
  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             if   Invitation ::take ( & data . E mail,   & conn )   | |   CONFIG . is_signup_allowed ( & data . E mail)   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 User ::new ( data . E mail. clone ( ) )  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             if   Invitation ::take ( & e mail,   & conn )   | |   CONFIG . is_signup_allowed ( & e mail)   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 User ::new ( e mail. clone ( ) )  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }   else   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					                 err ! ( "Registration not allowed or user already exists" )  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					             }  
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				
					@ -106,7 +107,7 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult { 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     } ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     // Make sure we don't leave a lingering invitation.
  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     Invitation ::take ( & data . E mail,   & conn ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     Invitation ::take ( & e mail,   & conn ) ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					     if   let   Some ( client_kdf_iter )   =   data . KdfIterations   {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				
					         user . client_kdf_iter   =   client_kdf_iter ;