Create a new client on login.

More clippy errors.
This commit is contained in:
Doug
2022-07-06 12:43:02 +01:00
parent 9925d73e7b
commit da277c4978
2 changed files with 25 additions and 18 deletions

View File

@@ -43,7 +43,7 @@ impl AuthenticationService {
.client
.as_ref()
.ok_or(AuthenticationError::ClientMissing)
.and_then(|client| Ok(client.homeserver()))
.map(|client| client.homeserver())
}
/// The OIDC Provider that is trusted by the homeserver. `nil` when
@@ -54,7 +54,7 @@ impl AuthenticationService {
.client
.as_ref()
.ok_or(AuthenticationError::ClientMissing)
.and_then(|client| Ok(client.authentication_issuer()))
.map(|client| client.authentication_issuer())
}
/// Whether the current homeserver supports the password login flow.
@@ -74,16 +74,12 @@ impl AuthenticationService {
let client = Arc::new(ClientBuilder::new())
.base_path(self.base_path.clone())
.username(username)
.build();
.build()
.map_err(AuthenticationError::from)?;
match client {
Ok(client) => {
let mut client_container = self.client_container.write();
client_container.client = Some(client);
Ok(())
}
Err(error) => Err(AuthenticationError::Generic { message: error.to_string() }),
}
let mut client_container = self.client_container.write();
client_container.client = Some(client);
Ok(())
}
/// Performs a password login using the current homeserver.
@@ -93,10 +89,22 @@ impl AuthenticationService {
password: String,
) -> Result<Arc<Client>, AuthenticationError> {
match self.client_container.read().client.as_ref() {
Some(client) => client
.login(username, password)
.and_then(|_| Ok(client.clone()))
.map_err(AuthenticationError::from),
Some(client) => {
let homeserver_url = client.homeserver();
// Create a new client to setup the store path for the username
let client = Arc::new(ClientBuilder::new())
.base_path(self.base_path.clone())
.homeserver_url(homeserver_url)
.username(username.clone())
.build()
.map_err(AuthenticationError::from)?;
client
.login(username, password)
.map(|_| client.clone())
.map_err(AuthenticationError::from)
}
None => Err(AuthenticationError::ClientMissing),
}
}

View File

@@ -89,9 +89,8 @@ impl Client {
pub fn supports_password_login(&self) -> anyhow::Result<bool> {
RUNTIME.block_on(async move {
let login_types = self.client.get_login_types().await?;
let supports_password = login_types.flows.iter().any(|login_type| match login_type {
get_login_types::v3::LoginType::Password(_) => true,
_ => false,
let supports_password = login_types.flows.iter().any(|login_type| {
matches!(login_type, get_login_types::v3::LoginType::Password(_))
});
Ok(supports_password)
})