async fn ensure_user_exists(
    base_url: &str,
    registration_shared_secret: &str,
    user: &User,
) -> Result<matrix_sdk::Client, Error> {
    debug!(
        "ensure_user_exists at {}: user {} with password {}",
        base_url, user.localname, user.password
    );
    use matrix_sdk::ruma::api::client::error::*;
    use matrix_sdk::ruma::api::error::*;
    let homeserver_url = reqwest::Url::parse(base_url)?;
    let config = ClientConfig::new();
    config
        .get_request_config()
        .retry_limit(RETRY_ATTEMPTS)
        .retry_timeout(std::time::Duration::new(TIMEOUT_SEC, 0));
    let client = matrix_sdk::Client::new_with_config(homeserver_url, config)?;
    match client
        .login(&user.localname, &user.password, None, None)
        .await
    {
        Err(matrix_sdk::Error::Http(matrix_sdk::HttpError::ClientApi(
            FromHttpResponseError::Http(ServerError::Known(err)),
        ))) if err.kind == ErrorKind::Forbidden => {
            debug!("Could not authenticate {}", err);
            // Proceed with registration.
        }
        Ok(_) => return Ok(client),
        Err(err) => return Err(err).context("Error attempting to login"),
    }
    register_user(base_url, registration_shared_secret, user).await?;
    client
        .login(&user.localname, &user.password, None, None)
        .await?;
    Ok(client)
}
/// Try to login with the user details provided. If login fails, try to register that user.
/// If registration then fails, returns an error explaining why, otherwise returns the login details.
Try to login with the user details provided. If login fails, try to register that user.
If registration then fails, returns an error explaining why, otherwise returns the login details.
Try to login with the user details provided . If login fails try to register that user . If registration then fails returns an error explaining why otherwise returns the login details .
async fn ensure_user_exists(
    base_url: &str,
    registration_shared_secret: &str,
    user: &User,
) -> Result<matrix_sdk::Client, Error> {
    debug!(
        "ensure_user_exists at {}: user {} with password {}",
        base_url, user.localname, user.password
    );
    use matrix_sdk::ruma::api::client::error::*;
    use matrix_sdk::ruma::api::error::*;
    let homeserver_url = reqwest::Url::parse(base_url)?;
    let config = ClientConfig::new();
    config
        .get_request_config()
        .retry_limit(RETRY_ATTEMPTS)
        .retry_timeout(std::time::Duration::new(TIMEOUT_SEC, 0));
    let client = matrix_sdk::Client::new_with_config(homeserver_url, config)?;
    match client
        .login(&user.localname, &user.password, None, None)
        .await
    {
        Err(matrix_sdk::Error::Http(matrix_sdk::HttpError::ClientApi(
            FromHttpResponseError::Http(ServerError::Known(err)),
        ))) if err.kind == ErrorKind::Forbidden => {
            debug!("Could not authenticate {}", err);
            // Proceed with registration.
        }
        Ok(_) => return Ok(client),
        Err(err) => return Err(err).context("Error attempting to login"),
    }
    register_user(base_url, registration_shared_secret, user).await?;
    client
        .login(&user.localname, &user.password, None, None)
        .await?;
    Ok(client)
}
async fn ensure_user_exists ( base_url : & str , registration_shared_secret : & str , user : & User , ) -> Result < matrix_sdk :: Client , Error > { debug ! ( " " base_url user localname user password ) ; use matrix_sdk :: ruma :: api :: client :: error :: * ; use matrix_sdk :: ruma :: api :: error :: * ; let homeserver_url = reqwest :: Url :: parse ( base_url ) ? ; let config = ClientConfig :: new ( ) ; config . get_request_config ( ) . retry_limit ( RETRY_ATTEMPTS ) . retry_timeout ( std :: time :: Duration :: new ( TIMEOUT_SEC , 0 ) ) ; let client = matrix_sdk :: Client :: new_with_config ( homeserver_url , config ) ? ; match client . login ( & user . localname , & user . password , None , None ) . await { Err ( matrix_sdk :: Error :: Http ( matrix_sdk :: HttpError :: ClientApi ( FromHttpResponseError :: Http ( ServerError :: Known ( err ) ) , ) ) ) if err . kind == ErrorKind :: Forbidden => { debug ! ( " " err ) ; // Proceed with registration. } Ok ( _ ) => return Ok ( client ) , Err ( err ) => return Err ( err ) . context ( " " ) , } register_user ( base_url , registration_shared_secret , user ) . await ? ; client . login ( & user . localname , & user . password , None , None ) . await ? ; Ok ( client ) }
Try to login with the user details provided.
Try to login with the user details provided .
base_url
&str
registration_shared_secret
&str
user
&User
base_url
&str
registration_shared_secret
&str
user
&User