async fn create(
    name: &str,
    password: &str,
    confirm_password: &str,
    email: Option<&str>,
    pg: &PgPool,
) -> Result<PartialPlayer> {
    let name = name.trim();
    let password = password.trim();
    let _confirm_password = confirm_password.trim();
    let _email = email.map(|e| e.trim());

    let salt = SaltString::generate(&mut OsRng);
    let argon = Argon2::default();

    let hash = argon
        .hash_password(password.as_bytes(), salt.as_ref())?
        .to_string();

    // If the player supplied an email, we will send them a confirmation email, but this exists
    // on a separate table until activated; thus we always apply default values to a new account.
    let account_record = sqlx::query!(
        "insert into accounts (encrypted_password)
        values ($1)
        returning id",
        hash
    )
    .fetch_one(&*pg)
    .await?;

    let player_record = sqlx::query!(
        "insert into players (account_id, name)
        values ($1, $2)
        returning id",
        account_record.id,
        name
    )
    .fetch_one(&*pg)
    .await?;

    Ok(PartialPlayer::new(
        player_record.id,
        Account::new(account_record.id),
    ))
}
/// Creates a new account and character.
Creates a new account and character.
Creates a new account and character .
async fn create(
    name: &str,
    password: &str,
    confirm_password: &str,
    email: Option<&str>,
    pg: &PgPool,
) -> Result<PartialPlayer> {
    let name = name.trim();
    let password = password.trim();
    let _confirm_password = confirm_password.trim();
    let _email = email.map(|e| e.trim());
    let salt = SaltString::generate(&mut OsRng);
    let argon = Argon2::default();
    let hash = argon
        .hash_password(password.as_bytes(), salt.as_ref())?
        .to_string();
    // If the player supplied an email, we will send them a confirmation email, but this exists
    // on a separate table until activated; thus we always apply default values to a new account.
    let account_record = sqlx::query!(
        "insert into accounts (encrypted_password)
        values ($1)
        returning id",
        hash
    )
    .fetch_one(&*pg)
    .await?;
    let player_record = sqlx::query!(
        "insert into players (account_id, name)
        values ($1, $2)
        returning id",
        account_record.id,
        name
    )
    .fetch_one(&*pg)
    .await?;
    Ok(PartialPlayer::new(
        player_record.id,
        Account::new(account_record.id),
    ))
}
async fn create ( name : & str , password : & str , confirm_password : & str , email : Option < & str > , pg : & PgPool , ) -> Result < PartialPlayer > { let name = name . trim ( ) ; let password = password . trim ( ) ; let _confirm_password = confirm_password . trim ( ) ; let _email = email . map ( | e | e . trim ( ) ) ; let salt = SaltString :: generate ( & mut OsRng ) ; let argon = Argon2 :: default ( ) ; let hash = argon . hash_password ( password . as_bytes ( ) , salt . as_ref ( ) ) ? . to_string ( ) ; // If the player supplied an email, we will send them a confirmation email, but this exists // on a separate table until activated; thus we always apply default values to a new account. let account_record = sqlx :: query ! ( " " hash ) . fetch_one ( & * pg ) . await ? ; let player_record = sqlx :: query ! ( " " account_record id name ) . fetch_one ( & * pg ) . await ? ; Ok ( PartialPlayer :: new ( player_record . id , Account :: new ( account_record . id ) , ) ) }
Creates a new account and character.
Creates a new account and character .
name
&str
password
&str
confirm_password
&str
email
Option<&str>
pg
&PgPool
name
&str
password
&str
confirm_password
&str
email
Option<&str>
pg
&PgPool