From 0faf414cd958137ac60a1f37288994f3a1441780 Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Mon, 29 Jan 2024 06:17:10 -0500 Subject: feat: Add change-password command & support on server (#1615) * Add change-password command & support on server * Add a test for password change * review: run format --------- Co-authored-by: Ellie Huxtable --- atuin-client/src/api_client.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'atuin-client/src') diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index dc835cfb..d53c9a36 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"); + } + } } -- cgit v1.3.1