pub async fn create_user(pool: &DBPool, username: String, email: String, password: String) -> Result<User> {
        prune_unverified_users(pool).await?;

        let username_exists = user_exists_for_username(pool, username.clone()).await?;
        let email_exists = user_exists_for_email(pool, email.clone()).await?;

        if username_exists {
            generic_err!("Username is in use")
        } else if email_exists {
            generic_err!("Email is in use")
        } else if username.len() < 3 || username.len() > 63 {
            generic_err!("Username must be between 3 and 63 characters")
        } else if email.len() < 5 || email.len() > 63 {
            generic_err!("Email must be between 5 and 63 characters")
        } else if password.len() < 8 || password.len() > 255 {
            generic_err!("Password must be at least 8 characters")
        } else {
            let password_hash = generic_service_err!(
                hash(password, DEFAULT_COST),
                "Failed to hash password");

            let mut res = generic_service_err!(
                sqlx::query_file_as!(User, "sql/user/create_user.sql", username.clone(), email.clone(), password_hash)
                .fetch_all(pool).await,
                "Failed to create new user");

            Ok(res.remove(0))
        }
    }
/// Creates a user and returns the resulting record
/// 
/// # Arguments
/// 
/// * `pool` - The database pool
/// * `username` - The user's username
/// * `email` - The user's email
/// * `password` - The user's password
Creates a user and returns the resulting record
Creates a user and returns the resulting record
pub async fn create_user(pool: &DBPool, username: String, email: String, password: String) -> Result<User> {
        prune_unverified_users(pool).await?;
        let username_exists = user_exists_for_username(pool, username.clone()).await?;
        let email_exists = user_exists_for_email(pool, email.clone()).await?;
        if username_exists {
            generic_err!("Username is in use")
        } else if email_exists {
            generic_err!("Email is in use")
        } else if username.len() < 3 || username.len() > 63 {
            generic_err!("Username must be between 3 and 63 characters")
        } else if email.len() < 5 || email.len() > 63 {
            generic_err!("Email must be between 5 and 63 characters")
        } else if password.len() < 8 || password.len() > 255 {
            generic_err!("Password must be at least 8 characters")
        } else {
            let password_hash = generic_service_err!(
                hash(password, DEFAULT_COST),
                "Failed to hash password");
            let mut res = generic_service_err!(
                sqlx::query_file_as!(User, "sql/user/create_user.sql", username.clone(), email.clone(), password_hash)
                .fetch_all(pool).await,
                "Failed to create new user");
            Ok(res.remove(0))
        }
    }
pub async fn create_user ( pool : & DBPool , username : String , email : String , password : String ) -> Result < User > { prune_unverified_users ( pool ) . await ? ; let username_exists = user_exists_for_username ( pool , username . clone ( ) ) . await ? ; let email_exists = user_exists_for_email ( pool , email . clone ( ) ) . await ? ; if username_exists { generic_err ! ( " " ) } else if email_exists { generic_err ! ( " " ) } else if username . len ( ) < 3 || username . len ( ) > 63 { generic_err ! ( " " ) } else if email . len ( ) < 5 || email . len ( ) > 63 { generic_err ! ( " " ) } else if password . len ( ) < 8 || password . len ( ) > 255 { generic_err ! ( " " ) } else { let password_hash = generic_service_err ! ( hash ( password DEFAULT_COST ) " " ) ; let mut res = generic_service_err ! ( sqlx query_file_as ( User " " username clone ( ) email clone ( ) password_hash ) fetch_all ( pool ) await " " ) ; Ok ( res . remove ( 0 ) ) } }
Creates a user and returns the resulting record
Creates a user and returns the resulting record
pool
&DBPool
username
String
email
String
password
String
pool
&DBPool
username
String
email
String
password
String