summaryrefslogtreecommitdiffstats
path: root/atuin-client
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-client')
-rw-r--r--atuin-client/src/api_client.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index dc835cfba..d53c9a364 100644
--- a/atuin-client/src/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -10,8 +10,9 @@ use reqwest::{
use atuin_common::{
api::{
- AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, LoginRequest,
- LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse,
+ AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest,
+ ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, StatusResponse,
+ SyncHistoryResponse,
},
record::RecordStatus,
};
@@ -359,4 +360,35 @@ impl<'a> Client<'a> {
bail!("Unknown error");
}
}
+
+ pub async fn change_password(
+ &self,
+ current_password: String,
+ new_password: String,
+ ) -> Result<()> {
+ let url = format!("{}/account/password", self.sync_addr);
+ let url = Url::parse(url.as_str())?;
+
+ let resp = self
+ .client
+ .patch(url)
+ .json(&ChangePasswordRequest {
+ current_password,
+ new_password,
+ })
+ .send()
+ .await?;
+
+ dbg!(&resp);
+
+ if resp.status() == 401 {
+ bail!("current password is incorrect")
+ } else if resp.status() == 403 {
+ bail!("invalid login details");
+ } else if resp.status() == 200 {
+ Ok(())
+ } else {
+ bail!("Unknown error");
+ }
+ }
}